I can quickly deduce from looking at this code that foos is some sort of collection of foo and foo does some sort of action.
The beauty of this code is that object.doThing() is now free to change its return type to any sort of iterable without breaking downstream code. Depending on how they handle the imports, Foo can move all over the package structure or even be changed to a new class Bar so long as it keeps the same contract. All of this will be caught by the compiler if there is an issue, which means the caller will have a weaker dependence on the callee's method signature (A win IMO).
12
u/covercash2 Mar 09 '16
It seems safer than that in the article.
More like:
We all know what those will compile to. Anything else will have to be declared explicitly, though only once:
instead of
Although, I agree with the sentiment that a superclass should be used in a lot of cases, and that fudges with this var syntax a bit.