"The 'l' suffix is easily confused with the digit '1' -- use 'L' for clarity". Grazie a questo warning "premuroso" del compilatore C#, il seguente quiz in Java preso dalla stessa Session TS-2575 di 2004 JavaOne Conference non ha tanto senso in C#:
6. "It's Elementary"
public class Elementary
{
public static void main(String[] args)
{
System.out.println(54321 + 5432l);
}
}
What Does It Print?
- A. -22430
- B. 59753
- C. 10864
- D. 108642
Program doesn’t say what you think it does!
Another Look
public class Elementary
{
public static void main(String[] args)
{
System.out.println(54321 + 5432l);
}
}
- 1 - the numeral one
- l - the lowercase letter el
How Do You Fix It?
We won’t insult your intelligence
The Moral
- Always use uppercase el (L) for long literals
- Lowercase el makes the code unreadable
- 5432L is clearly a long, 5432l is misleading
- Never use lowercase el as a variable name
- Not this: List l = new ArrayList();
- But this: List list = new ArrayList();
Lo so che non è rocket science :-) però per l'ennesima volta C# mostra di avere un "second mover advantage".