From your example it looks like you may be looking form something like
class Row<T extends Enum<T>> {
EnumMap<T, Object> map;
}
You can use this class for instance like
Row<MyEnum> row = new Row<>();
row.map.put(MyEnum.A, "foo");//OK
//row.map.put(YourEnum.D, "bar");// Error, `put` from this reference
// is meant to handle `MyEnum`
inside the Row class, it doesn't seem to let me loop through values in the standard way:
for (T col : T.values())
T is generic type which is erased at runtime to Object and Object doesn't have values() method. Maybe you should consider including Class<T> field which would store information at runtime which exactly Enum you are using. This class has getEnumConstants() method which is similar to values() method.
So your code can look like
class Row<T extends Enum<T>> {
EnumMap<T, Object> map;
Class<T> enumType;
public Row(Class<T> enumType){
this.enumType = enumType;
}
void showEnums(){
for (T col : enumType.getEnumConstants())
System.out.println(col);
}
}
and can be used for example this way
Row<MyEnum> row = new Row<>(MyEnum.class);
row.showEnums();
EnumhereT implements EnumMap<Enum<?>, Object> whatever.class Row<T extends Enum<T>>?