Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

int literal to byte

 
Stary Kapec
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2023
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Stary Kapec
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks you both ;-)
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic