I need to provide some funds from enum
and generic
s. Since enums cannot have type parameters (this is simply forbidden by grammar) and actually acts as members public static final
, I usually write something like this:
public class GenericEnumLikeClass<T>{
public static GenericEnumLikeClass<MyType> TYPE_INSTANCE;
public static GenericEnumLikeClass<AnotherType> ANOTHER_INSTANCE;
}
The fact is that I have never done anything like this before and, strictly speaking, I'm not sure of the correctness in terms of Java conventions. Will this be seen as something weird or is it the commmon method used when we need to extend enum-like behavior with Type Paramters
?
source
share