5.1
Kinds of Conversion
CONVERSIONS AND PROMOTIONS
which produces the output:
(int)12.5f==12
after float widening: 12.0
12.0*12==144.0
Math.sin(144.0)== 0.49102159389846934
5.1   Kinds of Conversion
Specific type conversions in Java are divided into six categories.
5.1.1   Identity Conversions
A conversion from a type to that same type is permitted for any type. This may
seem trivial, but it has two practical consequences. First, it is always permitted for
an expression to have the desired type to begin with, thus allowing the simply
stated rule that every expression is subject to conversion, if only a trivial identity
conversion. Second, it implies that it is permitted for a program to include redun 
dant cast operators for the sake of clarity.
The only permitted conversion that involves the type
boolean
 is the identity
conversion from
boolean
 to
boolean
.
5.1.2   Widening Primitive Conversions
The following 19 specific conversions on primitive types are called the
widening
primitive conversions
:
byte
to
short
,
int
,
long
,
float
, or
double
short
to
int
,
long
,
float
, or
double
char
to
int
,
long
,
float
, or
double
int
to
long
,
float
, or
double
long
to
float
 or
double
float
to
double
Widening primitive conversions do not lose information about the overall
magnitude of a numeric value. Indeed, conversions widening from an integral type
to another integral type and from
float
 to
double
 do not lose any information at
all; the numeric value is preserved exactly. Conversion of an
int
 or a
long
 value
to
float
, or of a
long
 value to
double
, may result in
loss of precision
 that is,
the result may lose some of the least significant bits of the value. In this case, the
54






footer




 

 

 

 

 Home | About Us | Network | Services | Support | FAQ | Control Panel | Order Online | Sitemap | Contact

java hosting

 

Our partners: PHP: Hypertext Preprocessor Best Web Hosting Java Web Hosting Inexpensive Web Hosting  Jsp Web Hosting

Cheapest Web Hosting Jsp Hosting Cheap Hosting

Visionwebhosting.net Business web hosting division of Web Design Plus. All rights reserved