Java function definition with brackets syntax

  • A+

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; 


String args[]; 


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.


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