• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

short primitive implicit cast

 
Ranch Hand
Posts: 163
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello racnhers,
I can understand that
short s =7;
compiles[as thers an implicit cast from int to short]
but why doesnt the argument-parameter combination behave the same

Any Reasons

Thanks

 
Ranch Hand
Posts: 10198
3
Mac PPC Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Prashant,

The reason why compilation fails is that all numeric literals which are whole numbers are of type int.
so in the line testShort(7); 7 is considered to be an int and your method definition shows that it takes short as a parameter but it actually requires an int.

Hope you understood it.
 
Ranch Hand
Posts: 2412
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Assignment conversion includes the implicit narrowing primitive conversions so , for example, this is legal.



However, method invocation conversion does not include the implicit narrowing primitive conversions.
 
Ranch Hand
Posts: 381
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
keith,

Assignment conversion includes the implicit narrowing primitive conversions so , for example, this is legal.
However, method invocation conversion does not include the implicit narrowing primitive conversions.


What you said is what we can see in the sample program posted by prashant.Can you point to JLS for justification.
reply
    Bookmark Topic Watch Topic
  • New Topic