~Abhishek~
passed SCJP1.5
Erez Pitchon wrote: Long L1 = 23; //Line 1
Short S1 = 23;
Erez Pitchon wrote:Hi
Why does the first line not compile while the second does?
Long L1 = 23;
Short S1 = 23;
The 23 in Line 1 is integer literal. For Long, you need to write 23L for the compiler to understand it is a Long value. Short s1 = 23 is acceptable since it occupies less memory than an integer.
• A narrowing primitive conversion followed by a boxing conversion may be
used if the type of the variable is :
- Byte and the value of the constant expression is representable in the type
byte.
- Short and the value of the constant expression is representable in the type
short.
- Character and the value of the constant expression is representable in the
type char.
All code in my posts, unless a source is explicitly mentioned, is my own.
All code in my posts, unless a source is explicitly mentioned, is my own.