• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

"==" and Number-Wrappers

 
Sasha Ruehmkorf
Ranch Hand
Posts: 115
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 100
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 115
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 233
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Sasha,

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

Richard
 
Arad Chear
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi


i hope its clear now
 
Sasha Ruehmkorf
Ranch Hand
Posts: 115
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic