1. The difference between "= =" and "Equeal"
The Hashcode method returns the hash code value of the object. This method is supported to provide some advantages to the hash table, for example, the Hashtable provided by Java.util.Hashtable. The general contract for Hashcode is that during Java application execution, when the Hashcode method is called multiple times on the same object, the same integer must be returned consistently, provided that the information used in the Equals comparison on the object has not been modified. The integer does not need to be consistent from one execution of an application to another execution of the same application. If two objects are equal according to the Equals (object) method, calling the Hashcode method on each object in two objects must produce the same integer result. The following conditions are not required: If two objects are not equal according to the Equals (Java.lang.Object) method, then calling the Hashcode method on any of the two objects must produce a different integer result. However, programmers should know that generating different integer results for unequal objects can improve the performance of the hash table. In fact, the Hashcode method defined by the object class does return different integers for different objects. (This is typically done by converting the object's internal address to an integer, but the JAVATM programming language does not require this implementation technique.) When the Equals method is overridden, it is often necessary to override the Hashcode method to maintain the general contract of the Hashcode method, which declares that the equality object must have an equal hash code.
1 Public Static voidMain (string[] args) {2 intI=0;3 intm=i;4M=m+1;5 System.out.println (i);6 System.out.println (m);7 8String a= "0";9String b=A;Tenb= "1"; One System.out.println (a); A System.out.println (b); - -Moneychangerequest MoneyChangeRequest1 =Newmoneychangerequest (); theMoneychangerequest1.setcardno ("1"); -Moneychangerequest MoneyChangeRequest2 =Newmoneychangerequest (); -Moneychangerequest2.setcardno ("1"); - +System.out.println (Moneychangerequest1.getcardno (). Hashcode () = =Moneychangerequest2.getcardno (). Hashcode ()); -}
Java Basic article