why it is not equal?
Integer i =new Integer (42);
Long l =new Long (42);
if(i.equals(1))
System.out.println("Equal");
else
System.out.println("NOT Equal");
Why it is Not Equal?can you explain me?
Integer i =new Integer (42);
Long l =new Long (42);
if(i.equals(1))
System.out.println("Equal");
else
System.out.println("NOT Equal");
Why it is Not Equal?can you explain me?
When you do
i.equals(l) - equals method of the Integer class will be called.
and equals method in Integer class is like dis
public boolean equals(Object obj) {
if (obj instanceof Integer) {
//compare the two objects and return the result
}
return false;
}
The two objects will be compared only if both of them are Integer types, other wise it will simply return false.
www.free-java-tutorials.com