eclipse-jdt / eclipse-jdt/eclipse.jdt.core
javac incompatible missing error: "Cannot cast from List<Object> to T"
- Dominant language
- Java
- Stars
- 237
- Forks
- 195
- Avg merge
- 1d 10h
- Merged PRs (30d)
- 49
Description
The following code compiles with ecj but fails with javac `error: incompatible types: List cannot be converted to T`:
```
> T interfaced() {return (T) Collections.emptyList();}
```
Interestingly it seems only to be incompatible when an interface involved while slightly other variants behave same as in javac:
```
package a;
import java.util.Collections;
import java.util.List;
@SuppressWarnings("unchecked")
public class A {
//ecj: Cannot cast from List to T:
//javac: error: incompatible types: List cannot be converted to T:
> T custom() {return (T) Collections.emptyList();}
//ecj: Cannot cast from List to T:
//javac: error: incompatible types: List cannot be converted to T:
> T abstrct() {return (T) Collections.emptyList();}
//ecj: passes:
//javac: error: incompatible types: List cannot be converted to T:
> T interfaced() {return (T) Collections.emptyList();}
//ecj: passes:
//javac: passes:
> T objectable() {return (T) Collections.emptyList();}
}
```
Who is right jdt or javac?
I would also be interested in clean compile-able solution - which does not need `@SuppressWarnings("unchecked") `and/or typecast `(T)`.
Contributor guide
Assessment
This issue has not been assessed yet.