This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line!
See this thread for details.
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

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 ;-)
Have you checked out Aspose?
subject: int literal to byte
It's not a secret anymore!