4
我正在使用HashMap,下面的方法显示了跟踪类类型的更改侦听器。 IDE发出警告类对象的通用类型规范
[rawtypes] found raw type: java.lang.Class
missing type parameters for generic class java.lang.Class<T>.
什么类型需要指定类来解决警告?
private HashMap<Class, Set<ChangeListener>> classChangeListeners;
/**
* Adds a ChangeListener to the listener list for the specified class type. The class type
* specified must be a subclass of {@link BusinessObject}.
*
* @param <T> the type of BusinessObject.
* @param cls the class type.
* @param listener the ChangeListener to be added.
*/
public <T extends BusinessObject> void addChangeListener(Class<T> cls, ChangeListener listener)
{
if (!classChangeListeners.containsKey(cls))
{
classChangeListeners.put(cls, new TreeSet<ChangeListener>());
}
classChangeListeners.get(cls).add(listener);
}
从你的代码看起来,显然Class <?扩展BusinessObject>将是最合适的。 – 2010-07-19 15:20:52
只要该方法记录的不变量实际上适用于Map本身(它没有明确记录),我同意...... – 2010-07-19 15:22:32
我想这取决于ChangeListener可以处理什么。如果它只能处理BusinessObjects,那么我会选择Carl的建议。如果没关系,我会写类>。 (一般来说,我更喜欢