Java generics conversion

Posted by LittleGreenMan on Stack Overflow See other posts from Stack Overflow or by LittleGreenMan
Published on 2010-06-05T12:56:34Z Indexed on 2010/06/05 13:02 UTC
Read the original article Hit count: 186

Filed under:
|

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");
  }

© Stack Overflow or respective owner

Related posts about java

Related posts about generics