`
thinktothings
  • 浏览: 769146 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

判断两个类是否相等

    博客分类:
  • Java
 
阅读更多


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));
		

	}

}

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics