aspose file tools*
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
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Implicit Widening aka Conversions ???
 
Similar Threads
FINAL VARIABLE
Primitive Value Assignment
compile time constant doubt
return type
Q from examulator.com