private <K> Map<K, Object> createMap(final Class<K> keyClass) {
final boolean isEnum = keyClass.isEnum();
if(isEnum) {
// The following two lines throw warnings
final Class<? extends Enum<?>> enumCls = (Class<? extends Enum<?>>)keyClass;
final Map<K, Object> map = (Map<K, Object>)new EnumMap(enumCls);
return map;
}
else{
final Map<K, Object> map = new HashMap<K, Object>();
return map;
}
}
Предупреждения
found : java.lang.Class<K>
required: java.lang.Class<? extends java.lang.Enum<?>>
final Class<? extends Enum<?>> enumCls = (Class<? extends Enum<?>>)keyClass;
^
T.java:9: warning: [unchecked] unchecked call to EnumMap(java.lang.Class<K>) as a member of the raw type java.util.EnumMap
final Map<K, Object> map = (Map<K, Object>)new EnumMap(enumCls);
^
T.java:9: warning: [unchecked] unchecked cast
found : java.util.EnumMap
required: java.util.Map<K,java.lang.Object>
final Map<K, Object> map = (Map<K, Object>)new EnumMap(enumCls);
^
3 warnings