• 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
  • Tim Cooke
  • Devaka Cooray
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Martijn Verburg
  • Frits Walraven
  • Himai Minh

Equals method

 
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi guys

I know this may sound like a stupid question, but i've tried to make sense of it, and was hoping that somebody could give me a helping hand.

I have been studying for the SCJP, using the Kathy Sierra and Bert Bates book.
the following code was segment was in the book, i have just put it on a class



The output that the book tells me i should be getting is:
same object
meaningfully equal

when i run the code i get the output:
meaningfully equal


This made me do a double take, so i checked my version of java
C:\>java -version
java version "1.5.0_10"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_10-b03)
Java HotSpot(TM) Client VM (build 1.5.0_10-b03, mixed mode, sharing)



Now as i understand it Java 1.5 changed the way that the == works so that for certain wrapper objects, and certain values it would return 'true'

have i got this by the complete wrong end of the stick?

thanks
Tim
 
Tim Sparg
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi guys

found a post that answered my questions...

Linkt to Topic

If you are interested
 
Ranch Hand
Posts: 637
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Answer also available @
https://coderanch.com/t/263605/java-programmer-SCJP/certification/Return-Type
 
Ranch Hand
Posts: 134
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
if you do Integer i1 = new Integer(10);
Integer i2 = i1;

then i1==i2 --> TRUE since it compares references to the Integer object while equals compares the value and not necessary that if equals is TRUE then == has to be true , though hashCode() has to be TRUE in that case.
 
joke time: What is brown and sticky? ... ... ... A stick! Use it to beat this tiny ad!
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic