File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "datatypes" Watch "datatypes" New topic


Andre Fean

Joined: Nov 04, 2003
Posts: 4
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
William Brogden
Author and all-around good cowpoke

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

Joined: Nov 04, 2003
Posts: 4
But that means it makes no sense to use for example a short in such a case.
I agree. Here's the link:
subject: datatypes
It's not a secret anymore!