Override equals method on a problem

Category: Java EE
 
zhaozhiqiang2009
2012-01-01 09:00:28

Sponsored Links
Who can say that the purpose of the next override this method, what is it /
usually what circumstances need to rewrite it

Sponsored Links

lengbingde
2012-01-01 09:10:10
This reply is sent automatically for display only just There were no other special effects
landlord [nick207 2008-07-05 22:22:51] Until the historical aggregated data (not including post):
Total Posts: 2 posting scores : 40
Results posted total: 0 ; Results posted a total score: 0 ;
no satisfactory statement posted: 0 ; without a satisfactory statement posted minutes: 0 ;
outstanding of Posts: 2 ; outstanding total score: 40 ;
Results posted Percentage: 0.00% Results of the percentage: 0.00% ;
no satisfactory statement posted rate: ----------------- ---- no satisfaction knot fraction: ---------------------
See here how to knot posted:
fenghuohou
2012-01-01 09:17:17
Father your class provides functionality not meet the requirements, or expanded, and enhance the functionality of the parent class!
gduforg
2012-01-01 09:35:23
Object in the equals method to achieve the following:
public boolean equals (Object obj) {
return (this == obj);
}
compare two objects are the same, but in reality, most of the content is the same as a comparison target, determine whether two objects are the same with == judgment object content is the same with the equals (), which is necessary to achieve their equals.
example, String override the equals method to compare two strings are the same.
look at a simple case, you should be able to understand:
public class Test {
public static void main (String [] ; args) {
Object o1 = new Object ();
Object o2 = new Object ();
System.out.println (o1 == o2);
System.out.println (o1.equals (o2));
String str1 = new String ("abc");
String str2 = new String ("abc");
System.out.println (str1 == str2);
System.out.println (str1.equals (str2));
}
}
objects for Object o1 and o2, should not be the same the object, so the results of the first two output statements are false
for objects of type String str1 and str2, nor is it the same object, so str1 == str2 is false, but because the two objects are identical So str1.equals (str2) is true
taste them again.
jc5205203314
2012-01-01 09:41:52
override the equals method also should pay attention to when you want to override the hashCode method generally, to ensure that equals to true two objects have the same hashcode.
Domain and server ip had changed since 8/23/2013. Suspend the user registration and posts for program maintenance.