This week's giveaway is in the EJB and other Java EE Technologies forum. We're giving away four copies of EJB 3 in Action and have Debu Panda, Reza Rahman, Ryan Cuprak, and Michael Remijan on-line! See this thread for details.
public static void main(String args)
Integer i=new Integer(4);
Integer y=new Integer(4);
checkToString cs = new checkToString(2);
checkToString c = new checkToString(2);
System.out.println(" Both objects are equal");
System.out.println(" Unequal objects ");
System.out.println(" i,y - Both objects are equal");
System.out.println(" i,y - Unequal objects ");
In my above class, i & y are giving true on using i.equals(y) and cs & c objects are giving false on using cs.equals(c). In both the cases we are not overriding equals() method. Can someone helps me here?
As I stated in the other thread where you asked this question, what we do in our class doesn't matter here. It's Sring's and Integers equals() methods that are being called (as we can see clearly from the code), so it's what String and Integer do with equals() that matters. And both of those classes override equals(), as you can see in their javadocs.