Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 795
Josh Stone Avatar asked May 23 '14 22:05

Josh Stone


1 Answers

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

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

like image 110
assylias Avatar answered Oct 11 '22 14:10

assylias