This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes datatypes Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "datatypes" Watch "datatypes" New topic
Author

datatypes

Andre Fean
Greenhorn

Joined: Nov 04, 2003
Posts: 4
Hi,
Let's say we have following code:

Why is it working for int and long and why I have to do a typecast for short and byte?

Thanks & regards
Andre
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12769
    
    5
The results of arithmetic operations are automatically promoted to int in these examples so you have to cast them back to byte or short.
Bill
Andre Fean
Greenhorn

Joined: Nov 04, 2003
Posts: 4
But that means it makes no sense to use for example a short in such a case.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: datatypes