12 as a constant in java is an int.
The reason for the long compilation of l = 12 is that it is automatically expanded to long.
EDIT: As for your comment, there is nothing wrong with auto-extension, use what makes your code clearer, but just know what happens when you do the math on primitives. For example:
int i = 1213;
long l = 112321321L * i;
Long ones will have a completely different meaning, unless you explicitly put this first number as long, because Java will treat it as an integer math and cause an overflow.
source
share