Autocloseable
should always be used with try-with-resources
. At least Intellij inspection suggests it.
So, if I have a code that produces Foo
that implements Autocloseable
I should do:
try (final Foo foo = getFoo()) {
foo.doSomething();
}
But what if I have function that returns Foo[]
? Or function that accepts Foo[]
(or Collection<Foo>
) as its argument?
How can I use it with try-with-resources
?
Looks at the following functions:
Foo[] getFoos();
doAll(Foo... foo);
I want to do something line doAll(getFoos())
How can I do that?