• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Dan's Wrapper Class Doubt

 
Ranch Hand
Posts: 231
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Friends,
The answer for this question is "c",but I am wondering why not "a,c".The two Integer objects i1,i2 are not equal and they might have equal or unequal hashcodes.So(h1 == h2),could return "true" or "false",you never know.Please correct me ..and lemme know where i am going wrong.

Thanks in Advance.
 
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

The two Integer objects i1,i2 are not equal



Are you saying i1.equals(i2) returns false? I suggest you try it.
 
Jas Oberai
Ranch Hand
Posts: 231
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Barry,
After going thru your reply,i understood where i was goin wrong.By saying not equal,i meant that i1,i2 are refering to two different objects on the heap,but i knew i1.equals(i2) is true as the contents were the same.And I was thinking that the hashcode is calculated depending upon the reference i.e "==".Actually,that was my stupidity..sorry!!!
 
The only cure for that is hours of television radiation. And this 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
    Bookmark Topic Watch Topic
  • New Topic