Josh Stone
Josh Stone

Reputation: 4448

Type inference limitations with lambda expressions

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

Answers (1)

assylias
assylias

Reputation: 328598

It is an eclipse bug. Both compile fine with Netbeans or javac.

It seems that Eclipse has quite a few issues with java 8...

Upvotes: 6

Related Questions