title: Number.valueOf() implementation for Java generics
body: <p>I have been using a <code>Collection</code> of number values and have implemented some related functionality (mapping x->y values, etc). So far I have made use of generics to allow any subclass of <code>Number</code> in the <code>Collection</code>. </p>
  
  <p>In this particular class I keep running into the problem that there is no easy way to cast to the generic. The usual methods like <code>Double.valueOf()</code> cannot be invoked because <code>Number</code> does not provide such a method.</p>
  
  <p>Is there a good way around this?</p>
  
  <p>I have found <a href="https://stackoverflow.com/questions/36368235/java-get-valueof-for-generic-subclass-of-java-lang-number-or-primitive">this post</a> and thought that would solve it, but I cannot pass the <code>Class.class</code> parameter to it.</p>
  
  <pre><code>public class myList&lt;T extends Number&gt; extends Collection&lt;T&gt; {
  
    @Override
    public boolean add(T value){
      // this is no problem
    }
  
    // What I want to do:
    public boolean add(double value){
      return this.add(T.valueOf(value)); 
    }
  
    // Using the example I found:
    public void add(double value){
      return this.add( (T) Ideone.parse(value, T.class) ); // no such option
    }
  
  
  }
  </code></pre>
  
  <p>Thanks in advance.</p>