如何在 Java 中打印任何类实例?类似于 Javascript 中的 JSON.stringify()。不需要 JSON,任何格式的输出都可以。
public class User {
public String name, password;
public int age;
public ArrayList<String> phones;
public static void login() {
//do something
}
}
User X = new User;
X.name = "john connor";
X.password = "skynet";
X.age = "33";
X.phones.add("1234567");
X.phones.add("7654321");
System.out.println(printClass(X))
应该输出如下内容:
{ name:"john connor", password: "skynet", age: "33", phones:
["1234567", "7654321"], login: void function() }