E
Eric Smith
I'm trying to write a generic class using an enumeration as a type
parameter, but I ran into trouble trying to iterate over the enumeration
values:
class Foo<E extends Enum<E>>
{
public void doSomething ()
{
for (E index: E.values ())
{
// do stuff here
}
}
}
The compiler says:
Foo.java:55: cannot find symbol
symbol : method values()
location: class java.lang.Enum<E>
for (E index: E.values ())
^
1 error
Does E not inherit the values() method of the enumeration type?
Is there some other way I can do this?
I'm also rather unclear on why various JDK classes use
<E extends Enum<E>> for their parameter; I can't quite seem to
grasp what it means. I tried just using <E extends Enum>, but the
compiler had the same complaint.
Any hints will be much appreciated!
Thanks!
Eric
parameter, but I ran into trouble trying to iterate over the enumeration
values:
class Foo<E extends Enum<E>>
{
public void doSomething ()
{
for (E index: E.values ())
{
// do stuff here
}
}
}
The compiler says:
Foo.java:55: cannot find symbol
symbol : method values()
location: class java.lang.Enum<E>
for (E index: E.values ())
^
1 error
Does E not inherit the values() method of the enumeration type?
Is there some other way I can do this?
I'm also rather unclear on why various JDK classes use
<E extends Enum<E>> for their parameter; I can't quite seem to
grasp what it means. I tried just using <E extends Enum>, but the
compiler had the same complaint.
Any hints will be much appreciated!
Thanks!
Eric