wood burning stoves 2.0*
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
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "int literal to byte" Watch "int literal to byte" New topic
Author

int literal to byte

Stary Kapec
Ranch Hand

Joined: Dec 04, 2005
Posts: 81
Hi,
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 ;-)
 
Don't get me started about those stupid light bulbs.
 
subject: int literal to byte