This week's book giveaway is in the JavaFX forum.
We're giving away four copies of Introducing JavaFX 8 Programming and have Herbert Schildt on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Introducing JavaFX 8 Programming this week in the JavaFX forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark ""==" and Number-Wrappers" Watch ""==" and Number-Wrappers" New topic

"==" and Number-Wrappers

Sasha Ruehmkorf
Ranch Hand

Joined: Mar 29, 2007
Posts: 115
I just don't understand what happens here:

I think it's strange, that == is not transitive.

Any idea where I can find an explanation of how the ==-operator is compiled exactly?
I haven't found any language-specification other than the java-api so far.
[ April 20, 2007: Message edited by: Sasha Ruehmkorf ]
sharan vasandani
Ranch Hand

Joined: Feb 22, 2007
Posts: 100
when either of the operands of == when using with Integer object is primitive,then Integer object is autoboxed to its primitive value and then compared.
Sasha Ruehmkorf
Ranch Hand

Joined: Mar 29, 2007
Posts: 115
Just found: "If the operands of an equality operator are both of numeric type, or one is of numeric type and the other is convertible to numeric type, binary numeric promotion is performed on the operands"

Really much to learn for the exam...
Richard Boren
Ranch Hand

Joined: Mar 01, 2001
Posts: 233
Hi Sasha,

Try this link Warpper, Boxing, == Huh??

Arad Chear
Ranch Hand

Joined: Jan 05, 2007
Posts: 98

i hope its clear now
Sasha Ruehmkorf
Ranch Hand

Joined: Mar 29, 2007
Posts: 115
Thanks for your answers.
Yes, it all cleared up. Don't know why but unboxing never came to my mind, I always thought of the primitive type being boxed and then compared to the Integer...
I agree. Here's the link:
subject: "==" and Number-Wrappers
It's not a secret anymore!