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 int literal to byte Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "int literal to byte" Watch "int literal to byte" New topic

int literal to byte

Stary Kapec
Ranch Hand

Joined: Dec 04, 2005
Posts: 81
Why is it possible to declare byte variable and then assign it an int literal like this:

But the method below invoked with int literal argument does not work.

I understand there is an implicit cast in the first two examples, but why the cast is absent in the third?
[ July 21, 2006: Message edited by: Jasiek Motyka ]
wise owen
Ranch Hand

Joined: Feb 02, 2006
Posts: 2023
Assignment Conversion vs. Method Invocation Conversion
Barry Gaunt
Ranch Hand

Joined: Aug 03, 2002
Posts: 7729
See also JLS Section 5.3

Notice that widening conversions (byte to int) are allowed but not narrowing conversions (int to byte).
[ July 21, 2006: Message edited by: Barry Gaunt ]

Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
Stary Kapec
Ranch Hand

Joined: Dec 04, 2005
Posts: 81
Thanks you both ;-)
I agree. Here's the link:
subject: int literal to byte
It's not a secret anymore!