• 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

Implicit Widening aka Conversions ???

 
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
class ImplicitWidening
{
public static void main(String[] args)
{
int i = 25;
short s2 = i;
byte b = i;
char c = i;

/*

---------- Javac ----------
ImplicitWidening.java:9: possible loss of precision
found : int
required: short
short s2 = i;
^
ImplicitWidening.java:10: possible loss of precision
found : int
required: byte
byte b = i;
^
ImplicitWidening.java:11: possible loss of precision
found : int
required: char
char c = i;
^
3 errors
Normal Termination
Output completed (0 sec consumed).

*/
}
}// Done

why do i get the errors in comment???
============================================================================
==========================================================================

why do i not get an error for the following??? What role does final play here???

class ImplicitWidening
{
public static void main(String[] args)
{
final int i = 25;
short s2 = i;
byte b = i;
char c = i;

}
}// done

============================================================================
Have A Nice Day !!!
 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Java performs an implicit narrowing conversion if certain conditions are satisfied.
Please go through this page
http://www.absolutejava.com/main-articles/data-type-conversions/


Thanks
Karthik
 
reply
    Bookmark Topic Watch Topic
  • New Topic