eclipse-jdt / eclipse-jdt/eclipse.jdt.core
Generics cast issue
- Dominant language
- Java
- Stars
- 237
- Forks
- 195
- Avg merge
- 1d 12h
- Merged PRs (30d)
- 47
Description
The code at https://github.com/Tiller/jdt-annot-issue/tree/genericscast gives the following error in eclipse (4.37 & 4.38 nightly, haven't tested before) but works with javac
> Cannot cast from Enum> to Test.MyEnum Test.java /test/src/main/java/test line 16 Java Problem
```
public void test() {
assertThatEquals((MyEnum) enumExpression.valueOf("test.Test.MyEnum", "A")).test(MyEnum.A);
}
public static Predicate assertThatEquals(T elm) {
return elm2 -> Objects.equals(elm, elm2);
}
public > T valueOf(String fqdn, String value) {
...
}
```
Workaround is to not cast but explicitly provide the type:
```
assertThatEquals(enumExpression.valueOf("test.Test.MyEnum", "A")).test(MyEnum.A);
```
(sorry for all the issues guys, I have had some time this week so I create what I have laying around, I have at most one other to create :D)
Contributor guide
Assessment
This issue has not been assessed yet.