Java variable return type of function in enum
<p>In an Enum I would like to associate a function to each element like:</p>

<pre><code>public enum EleType {
    INTEGER(Integer.class,rand -&gt; rand.nextInt()), 
    CHARACTER(Character.class, rand -&gt; (char) (rand.nextInt(26) + 'a'));

    private EleType(Class cl, Function&lt;Random, ?&gt; cr) { 
        this.classType = cl; 
        this.creator = cr;
    }
    public Class getClassType() { return classType; }
    public Function&lt;Random, ?&gt; getCreator() { return creator; }


    private final Class&lt;?&gt; classType;

    private final Function&lt;Random, ?&gt; creator;


}
</code></pre>

<p>The return type of the function (the question mark) should be the class of the respective element. So for <code>INTEGER</code>, the return type of the <code>Function</code> should be Integer and for <code>CHARACTER</code> it should be <code>Character</code>. How do I achieve this? If I leave it as it is with the questionmark and try to use it in <code>RandomList&lt;Integer&gt; randomList = new RandomList&lt;&gt;(eleType.getCreator(), 10);</code> where</p>

<pre><code>public class RandomList&lt;T&gt; {

    private List&lt;T&gt; list;


    public List&lt;T&gt; getList() {
        return list;
    }


    public RandomList (Function&lt;Random, T&gt; creator, int n) {
        list = new ArrayList&lt;T&gt;();

        Random rand = new Random();
        rand.setSeed(System.currentTimeMillis());

        for (int i = 0; i &lt; n; i++) {
           list.add(creator.apply(rand));
        }
    }
}
</code></pre>

<p>I receive an error message:</p>

<blockquote>
  <p>Type mismatch: cannot convert from <code>RandomList&lt;capture#2-of ?&gt;</code> to 
       <code>RandomList&lt;Integer&gt;</code>
  Cannot infer type arguments for <code>RandomList&lt;&gt;</code></p>
</blockquote>