Skip to content

Generics cast issue #4633

@tiller

Description

@tiller

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<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 <T> Predicate<T> assertThatEquals(T elm) {
        return elm2 -> Objects.equals(elm, elm2);
    }

    public <T extends Enum<T>> T valueOf(String fqdn, String value) {
      ...
    }

Workaround is to not cast but explicitly provide the type:

assertThatEquals(enumExpression.<MyEnum>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)

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions