Webinar: Evaluation - 05.12
Implicit type conversion, also known as "coercion", is an automatic type conversion by the compiler. Implicit conversions do not require any operator. They are automatically performed when a value is copied to a compatible type. In a mixed type expression, a subtype s will be converted to a supertype t or some subtypes s1, s2, ... will be converted to a supertype t (maybe none of the s{i} is of type t) at runtime so that the program will run correctly. For example:
double d;
long l;
int i;
if (d > i)
d = i;
if (i > l)
l = i;
if (d == l)
d *= 2;
Although d, l and i belong to different datatypes, they will be automatically converted to the same datatype each time a comparison or assignment is executed.
0