What do square brackets in Java method declarations mean?

bnf, context-free-grammar, java

Solution

The square brackets are to indicate the method returns an array. For example, you can write a method that returns an array of int as:

int method()[] { … }

Many people aren't familiar with this syntax though, and it's best avoided.

You'll find the complete syntax for java 7 here: http://docs.oracle.com/javase/specs/jls/se7/html/jls-18.html

Problem

The grammar for method declarations in Java is something like the following: Java method declaration BNF: ``` method_declaration ::= { modifier } type identifier "(" [ parameter_list ] ")" { "[" "]" } ( statement_block | ";" ) ``` And I am wondering what do the square brackets mean. - Can anyone give me an example? - Is method declarations in Java looks like above (What about generics)? - Where can I find complete and actual BNF grammar for Java?

Original source