I have an enum
public enum Days {
SUNDAY, MONDAY, TUESDAY, WEDNESDAY,
THURSDAY, FRIDAY, SATURDAY
}
I want to make a class which can take values of type Days. So I used Java Generics
public class State<T extend Days>
But there is an error
The type parameter T should not be bounded by the final type Days.
Final types cannot be further extended
How can I resolve this?
Don’t use a generics bound. There’s no need. Just use an unbounded type, like this:
And to use it:
This is a straightforward typed class that doesn’t need a bound.
The only bound that might make sense is a bound to an
enum:This version requires that the generic parameter be an
enum. With this version the above usage example would still compile, but this would not compile (for example):because
Stringis not anenum.