how to make my own custom container - no default constructor
<p>I am studying generics now and I wonder how to build a parametrized class that can store some data for me. I want to know because of c++ influence on me. Secondly, I wonder how ArrayList is built.</p>

<p>My problem is you cannot make new instance of a class that has no default constructor, i.e.  Integer. I know I should specialize my class in order to handle these classes individually. However, there is no specialization in Java as in c++.</p>

<p>How can I alter the code</p>

<pre><code>import java.lang.*;

class test {}

class generic&lt;T&gt; {
    private Class&lt;T&gt; type;
    T element;
    generic(Class&lt;T&gt; type) {
    this.type = type;
    try {
        element = type.newInstance();
    } catch (Exception e) {
        System.out.println("error " + e);
    }
    }
    static &lt;T&gt; generic&lt;T&gt; create(Class&lt;T&gt; type) {
    return new generic&lt;T&gt;(type);
    }
}

public class Generic {
    public static void main(String[] args) {
    generic&lt;Test&gt; test = generic.create(Test.class);
    System.out.println(test);
    }
}
</code></pre>

<p>so that it handles Integer instead of Test?</p>
