Monday, August 16, 2010

A fine and confusing error message from Java

public String myFirstMethod() {
String result = "Hello world";
return result;;

A straightforward piece of code that rudely produces a compile-time error "unreachable statement at line 3". "What's so unreachable about that line?" you might ask. Those experienced in the way of Java compilers simply smile and point out the double semi-colon. Accordingly to the compiler, there is an (empty) Java statement between the two semi-colons and it is never reached because the methods always returns before it reaches it.

If I had written writing that error messages, I might have made it say "double semi-colon on line 3".

1 comment:

Anonymous said...
This comment has been removed by a blog administrator.