aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes == doubt Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "== doubt" Watch "== doubt" New topic
Author

== doubt

shreya prabhu
Ranch Hand

Joined: Feb 10, 2007
Posts: 31
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

Joined: Oct 10, 2006
Posts: 49
xxxValue returns the primitive value of a Wrapper object, so your code essentially does this:



Their primitive values are equal.


EXCEL IN ALL YOU DO
shreya prabhu
Ranch Hand

Joined: Feb 10, 2007
Posts: 31
thanks a lot
John Lincoln
Ranch Hand

Joined: Feb 11, 2003
Posts: 192
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
 
subject: == doubt