This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Implicit Widening aka Conversions ??? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Implicit Widening aka Conversions ???" Watch "Implicit Widening aka Conversions ???" New topic
Author

Implicit Widening aka Conversions ???

Prashanth Lingala
Ranch Hand

Joined: Nov 13, 2004
Posts: 66
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 !!!


Have A Nice Day !!!
Karthik Vaidiswaran
Greenhorn

Joined: Jan 11, 2005
Posts: 16
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
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Implicit Widening aka Conversions ???
 
Similar Threads
Q from examulator.com
FINAL VARIABLE
return type
Primitive Value Assignment
compile time constant doubt