Using generic enum in enhanced for loop

From: Paul van Rossem (paul_at_timeware.nl)
Date: 02/06/05


Date: Sun, 06 Feb 2005 09:04:04 +0100

Could someone please explain to me why it is not possible to have the
following construct?

public class MyGenericClass<E extends Enum<E>>
{
   public MyGenericClass(E ge)
   {
      // ...
      for(E val: E.values()) // compile error
      { // ...
      }
   }
}

The compiler complains that E.values() doesn't exist:
"the method values() is undefined for the type E".
Is there a solution, or can't it just not be done and if so, why not?

Thanks, Paul.