Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

== doubt

 
shreya prabhu
Ranch Hand
Posts: 31
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Integer i=new Integer('1');
Character cc=new Character('1');
if(i.equals(cc)){
System.out.println("equals");
}
if(i.intValue()==cc.charValue()){
System.out.println("EQ");
}

this code prints EQ.but why is i.intValue()==cc.charValue() equal?
 
Chris Stann
Ranch Hand
Posts: 49
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
xxxValue returns the primitive value of a Wrapper object, so your code essentially does this:



Their primitive values are equal.
 
shreya prabhu
Ranch Hand
Posts: 31
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks a lot
 
John Lincoln
Ranch Hand
Posts: 192
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Also byte,short,char are int compatible.

If you see there is no constructor in Integer class which takes char as argument. So '1' is internaly converted to and it creates an Integer object.

let me know if my understanding is correct

thanks
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic