File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Doubt in implict conversion Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Reply Bookmark "Doubt in implict conversion" Watch "Doubt in implict conversion" New topic
Author

Doubt in implict conversion

sakthi moorthy
Ranch Hand

Joined: Oct 17, 2007
Posts: 54
byte b = 1;
char c = 2;
c = b;//not allowed

but if i make
final byte b=1;
then it works reason?
Panseer Kaur
Ranch Hand

Joined: Nov 01, 2007
Posts: 44
The reason it cannot covert it without it being final is because your byte variable could be negative, which is out of bounds for a char. By making it final you are stating that "a" 100% for sure will be positive.

If you change it to

final byte b = -104;
char c = 2;
c = b;

It will still throw the error because it needs to know you are giving it a positive number.
[ December 10, 2007: Message edited by: Panseer Kaur ]
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: Doubt in implict conversion
 
Similar Threads
RolesOfCompiler
byte
Byte
Casting
byte