Compile Error Using MutableClassToInstanceMap with Generics

Posted by user298251 on Stack Overflow See other posts from Stack Overflow or by user298251
Published on 2010-03-21T02:22:47Z Indexed on 2010/03/21 2:31 UTC
Read the original article Hit count: 319

Filed under:

I am getting the following compile error "The method putInstance(Class, T) in the type MutableClassToInstanceMap is not applicable for the arguments (Class, Number)" on the putInstance method call. Does anyone know what I am doing wrong?? Thanks!

public class TestMutableClassToInstanceMap {

    public final MutableClassToInstanceMap<Number> identifiers = MutableClassToInstanceMap.create();

    public static void main(String[] args) {
        ArrayList<Number> numbers = new ArrayList<Number>();
        numbers.add(new Integer(5));
        TestMutableClassToInstanceMap test = new TestMutableClassToInstanceMap(numbers);
    }

    public TestMutableClassToInstanceMap(Collection<Number> numbers){
        for (Number number : numbers) {
            this.identifiers.putInstance(number.getClass(), number); //error here
        }
        this.identifiers.putInstance(Double.class, 5.0); // This works
    }

}

© Stack Overflow or respective owner

Related posts about guava