• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

equals()-doubt

 
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Integer i=new Integer(42);
Long l=new Long(42);
Double d=new Double(42.0);
System.out.println("(i.equals(d)) : "+(i.equals(d)));
System.out.println("(d.equals(i)) : "+(d.equals(i)));


Both the expressions evaluate to false. but some mock exam results say that these result in true. its wrong rt???
 
Ranch Hand
Posts: 163
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You are right.
Wrapper class equals() method returns true,
if the argument is not null and arugement, invoking object must be same type, contains same value.

for example,
public boolean equals(Object obj) method of Byte class,
Compares this object to the specified object. The result is true if and only if the argument is not null and is a Byte object that contains the same byte value as this object
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic