Skip to content

Type mismatch for java files #235

@kiril-akshonau

Description

@kiril-akshonau

Hi guys.

I've faced with strange issue in my java class: eclipse can't compile code

    public static void main(String[] args) {
        List<Foo> foos = null;
        Optional.ofNullable(foos)
            .map(list -> list.stream().collect(Collectors.toMap(foo -> foo.getFoo(), foo -> foo)))
            .orElse(Collections.emptyMap());
    }
    private static class Foo {
        private String foo;
        public String getFoo() {
            return foo;
        }
    }

Compilation error: Type mismatch: cannot convert from Optional<Object> to <unknown>

Without groovy plugin everything compiles fine

As workaround I can define type of foo variable explicitly and everything compiles fine

.map(list -> list.stream().collect(Collectors.toMap((Foo foo) -> foo.getFoo(), foo -> foo)))

My system("fresh" eclipse installation from official site and groovy plugin):

eclipse.buildId=4.6.1.M20160907-1200
java.version=1.8.0_111
java.vendor=Oracle Corporation
Windows7 x64

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions