Using Intellij 13.1.4 and Java 8
Given the source code:
package my.foobar; import java.util.concurrent.ConcurrentMap;import java.util.stream.Collectors; import com.google.common.collect.ImmutableList;import com.google.common.collect.ImmutableSet;import lombok.ToString; publicclass FooBar { @ToString publicstaticclass Foo { private String foo; private String bar; public Foo(String foo, String bar) { this.foo = foo; this.bar = bar; } public String getFoo() { return foo; } publicvoid setFoo(String foo) { this.foo = foo; } public String getBar() { return bar; } publicvoid setBar(String bar) { this.bar = bar; } } publicstaticvoid main(String[] args) { final ImmutableList<Foo> foos = ImmutableList.of(new Foo("a", "b"), new Foo("b", "c")); final ConcurrentMap<Foo, ImmutableSet<String>> map = foos.stream() .collect(Collectors.toConcurrentMap( it -> it, // Incorrect "Incompatible return type Object in lambda expression" error it -> ImmutableSet.of(it.getBar()), (a, b) -> ImmutableSet.<String>builder().addAll(a).addAll(b).build() )); System.out.println("map = " + map); // the error appears not immediatelly, but after writing some more code, after the lambda expression is written }}
which compiles, runs and produces output:
map = {FooBar.Foo(foo=b, bar=c)=[c], FooBar.Foo(foo=a, bar=b)=[b]}
But Intellij shows an errror at
it -> it