读书人

判断两个种是否相等

发布时间: 2012-08-25 10:06:20 作者: rapoo

判断两个类是否相等


public class TestVo {
?
?
?private String vc2Key;
?
?
?
?
?

?@Override
?public boolean equals(Object obj) {
??//if(this.vc2Key.equals(((TestVo)obj).getVc2Key())){
??if(this.vc2Key==((TestVo)obj).getVc2Key()){
???return true;
??}else{
???return false;
??}
?}

?public String getVc2Key() {
??return vc2Key;
?}

?public void setVc2Key(String vc2Key) {
??this.vc2Key = vc2Key;
?}
?

}

?

?

?

?

?

?

?

public class Test {/** * @param args */public static void main(String[] args) {TestVo testVo1=new TestVo();testVo1.setVc2Key("aaa");TestVo testVo2=new TestVo();testVo2.setVc2Key("aaa");System.out.println(testVo1.equals(testVo2));}}

?

读书人网 >编程

热点推荐