I'm trying to understand the narrowing primitive conversion concept in Java. Here's what the JLS 5.1.3 says about it:
22 specific conversions on primitive types are called the narrowing primitive conversions:
short to byte or char
char to byte or short
int to byte, short, or char
long to byte, short, char, or int
float to byte, short, char, int, or long
double to byte, short, char, int, long, or float
Since there is the implicit conversion converting long
to int
, we can write the following code:
public static void main (String[] args) throws java.lang.Exception
{
int c = 88L; //Compilation fail
System.out.println(c);
}
But it doesn't work. Why? The narrowing conversion from long to int should have been applied.