forum

home / developersection / forums / how can i auto box this class?

How can I auto box this class?

Andrew Deniel 1804 05-Oct-2013

I've the following class:


public class IntegerKey extends Number implements Comparable<IntegerKey> {

    private Integer m_key;
    public IntegerKey(Integer key) {
        m_key = key;
    }
    public IntegerKey(int key) {
        m_key = key;
    }
}


I would like to use this class as Follow:

assume I have the following generics:

Map<IntegerKey, MyCache> map = new HashMap<IntegerKey, MyCache>();

map.put(5, new MyCache());


This doesn't compile, why?? I don't want to do:

map.put(new IntegerKey(5), new MyCache());

Thank you!


Updated on 05-Oct-2013
Can you answer this question?

Answer

1 Answers

Liked By