• 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:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Junilu Lacar
  • Liutauras Vilda
Sheriffs:
  • Paul Clapham
  • Jeanne Boyarsky
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
Bartenders:
  • Jesse Duncan
  • Frits Walraven
  • Mikalai Zaikin

equals()-doubt

 
Vidya Ramachandran
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???
 
Naresh Gunda
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
 
pie. tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic