Incorrect "Incompatible return type Object in lambda expression"

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;

public class FooBar {

    @ToString
    public static class Foo {
        private String foo;
        private String bar;

        public Foo(String foo, String bar) {
            this.foo = foo;
            this.bar = bar;
        }

        public String getFoo() {
            return foo;
        }

        public void setFoo(String foo) {
            this.foo = foo;
        }

        public String getBar() {
            return bar;
        }

        public void setBar(String bar) {
            this.bar = bar;
        }
    }

    public static void 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

1 comment
Comment actions Permalink

Oleg,

is fixed in 14 EAP, unfortunately EAP suffers from http://youtrack.jetbrains.com/issue/IDEA-128894.  

Sorry for the inconvenience
Anna

0

Please sign in to leave a comment.