Reputation: 4448
While Java 8's type inference seems much improved, I've hit on a possible limitation and I'm not sure if there's some workaround I'm missing. The scenario:
class Foo<T> {
<U> void apply(Function<T, Consumer<U>> bar) {}
}
class Bar {
void setBar(String bar){}
}
Foo<Bar> foo = new Foo<>();
This works:
foo.<String>apply(bar -> bar::setBar);
This does not:
foo.apply(bar -> bar::setBar);
Is there any way to get type inference to work in this sort of situation?
Upvotes: 7
Views: 530