eclipse-jdt / eclipse-jdt/eclipse.jdt.core
[compiler] Compile error with Eclipse, but not with javac
- Dominant language
- Java
- Stars
- 237
- Forks
- 195
- Avg merge
- 1d 10h
- Merged PRs (30d)
- 49
Description
The following code compiles with `javac`, but not with eclipse:
```
import java.util.ArrayList;
import java.util.List;
public class Instanceof {
interface A {
//
}
interface B extends A {
//
}
interface Foo {
A getX();
}
public void test() {
List> list = new ArrayList<>();
// Compile error in the following line:
// "Type capture#1 of ? extends Instanceof.A cannot be safely cast to Instanceof.A
if (list.get(0) instanceof B) { // <== compile error with Eclipse, but not with javac
// do something
}
// No compile error
A item = list.get(0);
if (item instanceof B) {
// do something
}
}
}
```
Is there a workaround without changing the code?
Contributor guide
Assessment
This issue has not been assessed yet.