Tim Peierls, a colleague on the JSR-201 expert group, shared the following Java enumerated type declaration with me. He described it as "line noise":
enum _{_,;;}
(Remember line noise? I think it has been a decade since I last used uucp or had to manually debug a ppp connection by sending atdt to the modem, so I don't see much line noise these days...)
Tim's examples always seem insightful or instructive. This is one of them, and it highlights a couple of important points about the syntax of enum declarations. So let's take this declaration a token at a time.
- enum: obviously, this is the keyword, like class or interface, that is used to declare an enum.
- _: The name of the enumerated type is just underscore. This is a silly thing to do, but it does make it look more like line noise.
- {: the body of an enumerated type is enclosed in curly braces, just as a class is.
- _: the second underscore is the name of the single value of this enumerated type. Again, this is silly, but legal, name, chosen to make the example amusing. Having a type and member both named underscore leads us to code like System.out.println(_._); which looks more like Morse code than Java!
- ,: the enum syntax requires a comma between the names of enumerated values, and allows a comma following the last one. Tim put this optional comma here to highlight this fact. (Tim and I both believe that this optional comma is a good thing, by the way: if you use it, it is easier to rearrange the order of constants or add new ones to the list without ending up with a missing comma.)
- ;: the semicolon separates the list of enumerated values from the optional class body of the enumerated type.
- ;: this second semicolon is an empty member declaration within the class body. I can't explain why empty members declarations are allowed, but I can site section 8.1.5 of the Java Language Specification. You can actually put any number of semicolons here.
- }: this is the closing curly brace that ends the type.
It is the optional bits of syntax that Tim has highlighted with this example. If we strip it down to just the required tokens, we're just left with an example that is not nearly as interesting:
enum _{_}
If you want to try it out yourself, here's the test program I wrote around Tim's enum:
public class linenoise {
enum _{_,;;}
public static void main(String[] args) {
System.out.println(_._);
}
}
Finally, Tim leaves us with an exercise for the reader:
enum _{_,;;} // if this were an emoticon, what would it mean?
If you have an answer, feel free to leave a comment.




Too much plastic surgery catches up with you sooner or later.
I was going to stay out of this, but:
"My Shar-Pei farts in your general direction."
interface ___{; ___ _ ( ___ ... ___ ) ;}
class __{{new __(){__[]__(__...__){return __(__);};}.__();};__(__...__){;};}
Unfortunately there seems to be a known bug in beta1 that causes javac to NPE.
I suppose you might be able to do something with an inner class __...
Oh, I think the point of spurious semicolons within a classes braces is for C/C++ programmers who like to place them randomly after close braces. IIRC, changes in the 1.4 javac made a requirement that empty statements (within blocks) be reachable.
Oops. Spot the last minute over embellishment.
Looks like a butt: System.out.println(_._)
What's next, emoticons in code? Java poetry?
;-)