In Java, integer literals are of type int by default. For some other types, you may suffix the literal with a case-insensitive letter like L
, D
, F
to specify a long, double, or float, respectively. Note it is common practice to use uppercase letters for better readability.
The Java Language Specification does not provide the same syntactic sugar for byte or short types. Instead, you may declare it as such using explicit casting:
byte foo = (byte)0;
short bar = (short)0;
In your setLongValue(100L)
method call, you don't have to necessarily include the L
suffix because in this case the int literal is automatically widened to a long. This is called widening primitive conversion in the Java Language Specification.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…