Java generics conversion
- by LittleGreenMan
I have build a generic datacontainer and now I want to manipulate data depending on their type. However, I get an incompatable types warning. What am I doing wrong?
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");
}