Skip to content

Type mismatch with generic wildcard #4635

@tiller

Description

@tiller

With Eclipse 4.37 & 4.38M2 nightly, the following code:

public class Test {
    static class Obj<T> {
    }

    public static void main(String[] args) {
        String arg = "";

        Stream<Obj<?>> stream11 = Stream.of(newObj());
        Stream<Obj<?>> stream21 = Stream.of(newObj2(arg));

        Stream<Obj<?>> stream12 = Stream.of(newObj(), newObj());
        Stream<Obj<?>> stream22 = Stream.of(newObj2(arg), newObj2(arg));

        //Stream<Obj<?>> stream11f = Stream.of(newObj()).filter(Objects::nonNull); // javac & eclipse KO
        //Stream<Obj<?>> stream21f = Stream.of(newObj2(arg)).filter(Objects::nonNull); // javac & eclipse KO

        Stream<Obj<?>> stream12f = Stream.of(newObj(), newObj()).filter(Objects::nonNull);
        Stream<Obj<?>> stream22f = Stream.of(newObj2(arg), newObj2(arg)).filter(Objects::nonNull); // javac OK, eclipse KO
    }

    public static Obj<?> newObj() {
        return new Obj<>();
    }

    public static <T> Obj<?> newObj2(T arg) {
        return new Obj<>();
    }
}

Gives an inconsistent result for stream22f where it works on javac but not on eclipse :

Type mismatch: cannot convert from Stream<Test.Obj> to Stream<Test.Obj<?>> Test.java /test/src/main/java/test line 25 Java Problem

(that's my last issue, thanks guys for your work)

Metadata

Metadata

Labels

compilerEclipse Java Compiler (ecj) related issues

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions