我已经构建了一个通用的数据容器,现在我想根据它们的类型来操作数据。但是,我收到了不兼容的类型警告。我究竟做错了什么?Java泛型转换
Type _Value;
public void set(Type t) throws Exception {
if (_Value instanceof Integer
&& t instanceof Integer) {
_Value = (((Integer) t
- _MinValue + getRange())
% getRange()) + _MinValue;
}
else if (_Value instanceof Boolean
&& t instanceof Boolean) {
_Value = t;
}
else throw new Exception("Invalid type");
}
显示如何定义类以及如何构造实例。 – 2010-06-05 12:59:28