纯数据类,没什么需要测试的。 public final class Address { public final String country; public final String province; public final String city; public final String street; public final String postcode; public Address(String country,String province,String city,String street,String postcode){ this.country = country; this.province = province; this.city = city; this.street = street; this.postcode = postcode; } @Override String toString(){ return String.format("Address[country:%s, province:%s, city:%s, street:%s, postcode:%s]",country,province,city,street,postcode); } }
public final class Address {
public final String country;
public final String province;
public final String city;
public final String street;
public final String postcode;
public Address(String country,String province,String city,String street,String postcode){
this.country = country;
this.province = province;
this.city = city;
this.street = street;
this.postcode = postcode;
} @Override String toString(){
return String.format("Address[country:%s, province:%s, city:%s, street:%s, postcode:%s]",country,province,city,street,postcode);
}
}
return String.format("Address[country:%s, province:%s, city:%s, street:%s, postcode:%s]",country,province,city,street,postcode);
}
这一句是什么意思!
return String.format("Address[country:%s, province:%s, city:%s, street:%s, postcode:%s]",country,province,city,street,postcode);
} @Override public String toString(){
return String.format("Address[country:%s, province:%s, city:%s, street:%s, postcode:%s]",country,province,city,street,postcode);
}
少写了 public。 类实例的字符串表示。
System.out.println(new Address(...));会调用 toString 方法。
return this.toString().hashCode();
}@Override public boolean(Object o){
if(o == null) return false;
if(o == this) return true;
if(o.getClass() == Address.class){ return this.toString().equals(((Address)o).toString());
return false;
}
你就去一个个的把内容加上就好了