How to use java.lang.Number polymorphically
<p>I'm trying to use java.lang.Number polymorphically:
I have a List where I put multiple Double, Integer, etc. instances, and then I want to polymorphically do arithmetic operations on them (for example double every Number).</p>

<p>We don't have the auto-boxing ability with java.lang.Number and I'm not figuring out a better way to do this without the - not so polymorphic - method  multiply(Number n, int factor) in the sample source code that follows... and with this implementation we would need a method for each arithmetic operation (add, subtract, etc.)</p>

<hr>

<p>EDIT - ENHANCE QUESTION: if we think on the java.lang.Number from a abstraction perspective, we would think that any Number can be part of arithmetic operations but yet again it doesn't seem to exist a simple way to add/subtract/multiply/etc x to a list of Number, independently of their type (Integer, Double, Short...) </p>

<hr>

<p>Any better ideias?
Thanks in advance ;)</p>

<p>Sample source code:</p>

<pre><code>public class NumberTest {

    private List&lt;Number&gt; list = new ArrayList&lt;Number&gt;();    

    public static void main(String args[]) {
        new NumberTest().start();

    }

    protected void start() {
        this.fillList();
        Number num;
        for (int i = 0; i &lt; list.size(); i++) {
            num = this.multiply(list.get(i), 2);
            list.set(i, num);
        }

        System.out.println(this.toString());
    }

    private void fillList() {
        list.add(new Byte((byte) 12));
        list.add(new Short((short) 20));
        list.add(new Integer(30));
        list.add(new Long(40));
        list.add(new Float(50.123));
        list.add(new Double(60.123));
    }

    private Number multiply(Number n, int factor) {
        if (n instanceof Byte) {
            n = n.byteValue() * factor;
        } else if (n instanceof Short) {
            n = n.shortValue() * factor;
        } else if (n instanceof Integer) {
            n = n.intValue() * factor;
        } else if (n instanceof Long) {
            n = n.longValue() * factor;
        } else if (n instanceof Float) {
            n = n.floatValue() * factor;
        } else if (n instanceof Double) {
            n = n.doubleValue() * factor;
        }
        return n;
    }

    @Override
    public String toString() {
        String result = "";
        for (Number num : list) {
            result += num+"\n";
        }
        return result;
    }
</code></pre>
