Alion Bada wrote:I was so impressed by the way of accessing an array through method name...(myArray()[0] )
I agree the syntax seems a little bit weird, but actually there's no real difference between this and method chaining as in the following code snippet
The
append() method returns a
StringBuilder, so you can invoke any
StringBuilder method on a method invocation. And that's how you can chain different method invocations. And the same applies to your example: the
myArray() method returns a reference variable to an array, so any method and/or operator you can invoke on such a reference variable can be used in combination with the method invocation as well. Writing
myArray()[0]++; is functionally equivalent with