If you use Eclipse Collections and modify getBars () to return a MutableList or something similar, you can write:
MutableList<String> names = foo.getBars().collect(new Function<Bar, String>()
{
public String valueOf(Bar bar)
{
return bar.getName();
}
});
If you retrieve a function as a constant in Bar, it is reduced to:
MutableList<String> names = foo.getBars().collect(Bar.TO_NAME);
With Java 8 lambdas, you don't need a function at all.
MutableList<String> names = foo.getBars().collect(Bar::getName);
getBars(), ListAdapter.
MutableList<String> names = ListAdapter.adapt(foo.getBars()).collect(Bar.TO_NAME);
. Eclipse.