public class Field {
private String s1;
private String s2;
private int a1;
public String getS1() {
return s1;
}
public void setS1(String s1) {
this.s1 = s1;
}
public String getS2() {
return s2;
}
public void setS2(String s2) {
this.s2 = s2;
}
public int getA1() {
return a1;
}
public void setA1(int a1) {
this.a1 = a1;
}
}
Field u1 = new Field("f1", "f2", 1);
Field u2 = new Field("f1", "f2", 2);
假如实例化两个Field类,在第一个第二个相同的情况下,比较第三个的大小,如果哪个大就赋值覆盖小的那个实例的对应的第三个属性,怎么可以做到呢?
提供一种思路,实现Comparable接口