JAVA FAIL

Friday, November 21, 2008

SWITCH FAIL

public class Foo
{
public void foo(final long value)
{
switch(value) {
case 0:
break;
default:
break;
}
}
}


$ javac -Xlint:all Foo.java
Foo.java:5: possible loss of precision
found : long
required: int
switch(value) {
^
1 error


The argument to switch() must be an int, promotable to int, or an enumeration. So long can't be used. Good thing Java doesn't have to worry about things like handling 64-bit values or anything.