[enhanced-enums]: Enhanced enums failure with raw types?

Maurizio Cimadamore maurizio.cimadamore at oracle.com
Mon Sep 11 20:38:19 UTC 2017

On 11/09/17 20:25, B. Blaser wrote:
> What do you think of this way of representing heterogeneous options?
I'm not convinced it works? In your example you have:

         EnumSet<G<Object>> g3 = EnumSet.allOf(G.class);

So, while it's true that the LHS is now well-formed, I think inference 
would still fail - as you get one equality constraint like this:

E = G<Object> (from LHS)

but another constraint is like this

E = G (from actual argument, whose type is Class<G> - raw type parameter)

And these two constraints are incompatible. You'd probably need to throw 
in a cast near G.class.

That said, even looking at the LHS, using Object (or any other 'ground' 
type that happens to be compatible with how the enum is used) works, but 
only until there's no bound in the enum declaration. If there's a bound, 
and the bound is a ground type you are still ok - as you can use that 
instead of Object, but if the bound is an f-bound, then I think you are 
out of luck.


More information about the amber-dev mailing list