eclipse-jdt / eclipse-jdt/eclipse.jdt.core

Diamond operator type inference fails under javac but not ECJ

Open
#3,588 3 comments 0 reactions 0 assignees View on GitHub
javac rawtypes
Dominant language
Java
Stars
237
Forks
195
Avg merge
1d 12h
Merged PRs (30d)
47

Description

The following minimal example produces a compiler error under javac but not ECJ:

```java
import java.util.List;
import java.util.ArrayList;
import java.util.Arrays;

public class HelloWorld {
public static void main(String... args) {
Class[] classes = new Class[] { String.class, List.class };
List> asdf = new ArrayList<>(Arrays.asList(classes));
}
}
```

Here's the error that javac gives:

```
HelloWorld.java:9: error: incompatible types: cannot infer type arguments for ArrayList<>
List> asdf = new ArrayList<>(Arrays.asList(classes));
^
reason: cannot infer type-variable(s) E,T
(argument mismatch; List cannot be converted to Collection>)
where E,T are type-variables:
E extends Object declared in class ArrayList
T extends Object declared in method asList(T...)
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.