File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Problem with casting Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Problem with casting " Watch "Problem with casting " New topic
Author

Problem with casting

vinayak manda
Ranch Hand

Joined: Jul 27, 2004
Posts: 31
Are there different rules for casting for different types of operators(like assignment and compound operators)
I mean when
byte b=1;
long l=1000;
b=(byte)l; //compiler asks for casting here.

And when
byte b=1;
long l=1000;
b+=l; //which is b=b+l,and the result of b+l here is long,then why doesn't compiler ask for casting when assigning to long to byte as above exmaple.And will byte store 1000.

Please help,
Peter den Haan
author
Ranch Hand

Joined: Apr 20, 2000
Posts: 3252
is not equivalent tobut to - Peter
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Problem with casting