, We can convert the instances of compatible types, which creates a new value from the old one.
int x = 5;
short y = (short)x;
In the above example, we are converting a 32 bit integer
) to a 16 bit integer
) by using cast (short)
of that type.
conversions doesn't need any guarantee of the compiler for the successful conversion.
There might be a loss of information while converting explicitly.
Asked In: Spotted While Learning |