When would you put a semicolon after a method closing brace?

It’s allowed by the grammar as a concession to harmless syntax errors, but it’s not generally used and doesn’t mean anything different (than leaving the semicolon out).

Just as a }; inside a method (such as after an if block) is a null statement and is allowed, an errant semicolon outside a method is considered a null declaration and is allowed.

Specifically, the following production from the Java Language Specification allows this:

ClassBodyDeclaration:
  ; 
  [static] Block
  ModifiersOpt MemberDecl

Leave a Comment