public class Test {
public static void main(String[] args) {
User s=new User();
s.setId(1);
System.out.println("s is"+s);
}
}
public class User
{
private Integer id;
private String firstname;
private String lastname;
private Integer parentID;
private int age;
private Set childrens;
private User user;
@Override
public String toString() {
// TODO Auto-generated method stub
return "id is"+this.id;
}
}
注释:当输出一个类时,java默认调用的是该类的toString方法,输出时com.test.bean.User@c17164,可以改写该方法输出你想要的值