Java function definition with brackets syntax

  • A+
Category:Languages

Was looking in the source for ByteArrayOutputStream, and I saw this function:

public synchronized byte toByteArray()[] {     return Arrays.copyOf(buf, count); } 

Where is this syntax documented? I mean the [] in front of the function. Is this the same as in declaring a regular array where the bracket can go after the name of the array or before?

String[] args; 

Or

String args[]; 


Here:

MethodDeclarator:     Identifier ( [FormalParameterList] ) [Dims] 

...

The declaration of a method that returns an array is allowed to place some or all of the bracket pairs that denote the array type after the formal parameter list. This syntax is supported for compatibility with early versions of the Java programming language. It is very strongly recommended that this syntax is not used in new code.

Comment

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: