I’m reviewing java and stumbled upon something like the following block of code
public Foo example()
Foo bar = new Foo(...);
...
return new Foo[]{bar};
what does Foo[]{bar} mean in this context? Is it returning an array of Foo objects populated by bar? Seems to be something really trivial but I’m not sure what how to search for it.
Yes, it’s creating an array with a single element, initially set to the value of
bar. You can use this syntax for more elements though, e.g.This is an ArrayCreationExpression, as specified in section 15.10 of the Java Language Specification, using an ArrayInitializer as specified in section 10.6.