Java (Android) - types, generics, constructor signature, retrieving references to Class
<p>I've searched SO and found several answers obviously related to my question, and have read the following as well:</p>

<p><a href="http://docs.oracle.com/javase/tutorial/java/generics/erasure.html" rel="nofollow">http://docs.oracle.com/javase/tutorial/java/generics/erasure.html</a>
http://www.artima.com/weblogs/viewpost.jsp?thread=208860
<a href="http://docs.oracle.com/javase/tutorial/extra/generics/index.html" rel="nofollow">http://docs.oracle.com/javase/tutorial/extra/generics/index.html</a>
http://docs.oracle.com/javase/tutorial/java/generics/genmethods.html</p>

<p>But they're a little over my head (I'm fairly new to Java and Android).</p>

<p>I'm trying to understand how to implement a generic in a custom class.  I think an example would be the best way to explain it.</p>

<p>Let's say I start off with this base class:</p>

<pre><code>import java.util.ArrayList;

import android.content.Context;
import android.widget.ImageView;

public class ViewPool {

    private ArrayList&lt;ImageView&gt; employed;
    private ArrayList&lt;ImageView&gt; unemployed;

    private Context context;

    public ViewPool(Context context){

        this.context = context;

        employed = new ArrayList&lt;ImageView&gt;();
        unemployed = new ArrayList&lt;ImageView&gt;();

    }

    public ImageView employView(){      
        ImageView v;
        if(unemployed.size() &gt; 0){
            v = unemployed.get(0);
            unemployed.remove(v);
        } else {
            v = new ImageView(context);
        }
        employed.add(v);
        return v;
    }

    public void retireView(ImageView v){
        if(employed.contains(v)){
            employed.remove(v);
            unemployed.add(v);
        }
    }
}
</code></pre>

<p>Now let's say I want to modify the above to work with any View type, passed like:</p>

<pre><code>new ViewPool&lt;ImageView&gt;(this);
</code></pre>

<p>or...</p>

<pre><code>new ViewPool&lt;TextView&gt;(this);
</code></pre>

<p>How would I rewrite the class listed above to accept types like that?  My initial attempts, something like this next code block, failed for what are probably obvious reasons...</p>

<pre><code>public class ViewPool&lt;E&gt; {
...
    public E employView(){      
        E v;
        if(unemployed.size() &gt; 0){
            v = unemployed.get(0);
            unemployed.remove(v);
        } else {
            v = new E(context);  // this line's obviously bad, but not sure what would be correct
        }
        employed.add(v);
        return v;
    }
...
</code></pre>

<p>Thanks</p>
