An implicit cast means you don't have to write code for the cast
An implicit cast happens when you're doing a widening conversion.
public class MainClass{
public static void main(String[] argv){
int a = 100;
long b = a; // Implicit cast, an int value always fits in a long
}
}
An explicit casts looks like this:
public class MainClass{
public static void main(String[] argv){
float a = 100.001f;
int b = (int)a; // Explicit cast, the float could lose info
}
}
Impossible Conversions
Any primitive type to any reference type
The null value to any primitive type
Any primitive to boolean
A boolean to any primitive
|