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

ecj 4.36 compiles ok, javac does not (generics)

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

Description

ecj does not find errors in code below. javac brings following error:

ECJ_JAVAC_DIFF.java:23: Fehler: Methode create in Klasse ECJ_JAVAC_DIFF kann nicht auf die angegebenen Typen angewendet werden.
create(c);
^
Erforderlich: Class>
Ermittelt: Class
Grund: Typvariable(n) T nicht ableitbar
(nicht übereinstimmende Argumente; Class kann nicht in Class> konvertiert werden)
Dabei ist T eine Typvariable:
T erweitert Serializable, deklariert in Methode create(Class>)
Dabei ist CAP#1 eine neue Typvariable:
CAP#1 erweitert Supplier aus Erfassung von ? extends Supplier
1 Fehler

```
import java.io.Serializable;
import java.lang.reflect.InvocationTargetException;
import java.util.function.Supplier;

public class ECJ_JAVAC_DIFF {
public T
create(final Class> c) {
try {
final Supplier s = c.getConstructor().newInstance();
return s.get();
} catch (InstantiationException
| IllegalAccessException
| IllegalArgumentException
| InvocationTargetException
| NoSuchMethodException
| SecurityException e) {
throw new RuntimeException(e);
}
}

public void
doSomething(final Class> c) {
create(c);
}
}
```

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.