Java 8 Bug

Zhong Yu zhong.j.yu at
Sun Nov 17 08:50:29 PST 2013

Hi Alan, the code compiles in jdk8 build 115. (I notice that the email is from
9 days ago)

However, I doubt that it *should* compile even in Java7. Essentially,
we have a capture variable `x` whose upper bound is `Enum`, and we
need to test `x<:Enum<?>`, which should fail.


BTW, Your method signature is probably better off as

    <E extends Enum<E>> Map<String, Enum<E>>
    parseEnumConstants(Class<E> clazz)

An interesting question is, given a `Class<?>` object, how do we
convince compiler that it is a `Class<e>` for some `e` that
`e<:Enum<e>`? I think there are pretty good answers in

Zhong Yu

On Fri, Nov 8, 2013 at 9:58 AM, Alan <alan at> wrote:
> Sorry if this isn't the correct list ! If not, please tell me where I
> should post this bug.
> The following code works in jdk1.7.0_21 but not in jdk1.8.0
> private static <E extends Enum<?>> Map<String, Enum<?>>
> parseEnumConstants(Class<E> clazz) {} = ...
> Class<?> type = ...
> parseEnumConstants(type.asSubclass(Enum.class))
> Map<String, Enum<?>> universe = (Map<String, Enum<?>>)
> parseEnumConstants(type.asSubclass(Enum.class));
>    required: Class<E>
>    found: Class<CAP#1>
>    reason: cannot infer type-variable(s) E,U
>      (argument mismatch; Class<CAP#2> cannot be converted to Class<CAP#3>)
>    where E,U are type-variables:
>      E extends Enum<?> declared in method <E>parseEnumConstants(Class<E>)
>      U extends Object declared in method <U>asSubclass(Class<U>)
>    where CAP#1,CAP#2,CAP#3 are fresh type-variables:
>      CAP#1 extends Enum from capture of ? extends Enum
>      CAP#2 extends Enum from capture of ? extends Enum
>      CAP#3 extends Enum from capture of ? extends Enum
> What is really unusual is that I can't see how this error can be
> occuring - none of the method signatures have changed!

More information about the lambda-dev mailing list