Java Language Specification Bug

Just to be clear, this is a documentation bug in the JLS, not a bug in the language. Check out this example from Section 4.11 of the Java Language Specification:

void <S> loop(S s) {
  this.<S>loop(s);
}

That won’t compile for me. I have to put the <S> before the void, like this:

<S> void loop(S s) {
  this.<S>loop(s);
}

Simplify the Code

Now that the bug is fixed, IDEA warns that the second <S> is not required. “this.” is also extra noise, so you could simplify the recursive loop to this:

<S> void loop(S s) {
  loop(s);
}

Although I think they may have wanted the explicit <S> in there just to show the syntax.

Good luck running this example. :-)

See my next post for the reason why I ran across this little gem…


One Response to “Java Language Specification Bug”

Fred Says:

BTW: Nobody knows about it but you can use this in enums.
public enum Birds {
tweety(Yellow.class), perot(Green.class);

<T> Birds(Class<T> colorClass) {
new ColorHandler<T>();
}
}

Leave a Reply