Collection of generic objects not working as intended
<p>I have my own generic class which goes like this:</p>

<pre><code>C1&lt;T&gt; {
    T value;
    ...
    void setValue(T val) {
        this.avlue = val;
    }
}
</code></pre>

<p>Somewhere else i have this collection:</p>

<pre><code>  List&lt;C1&gt; list;
</code></pre>

<p>Then in a different piece of code I instantiate some objects of type C1 like this:</p>

<pre><code>C1&lt;Integer&gt; a;
C1&lt;Float&gt; b;
C1&lt;String&gt; c;
...
</code></pre>

<p>Later i put them in the list;</p>

<pre><code>list.add(a);
list.add(b)
...
</code></pre>

<p>The next thing i do is this:
iterate over list doing this:</p>

<pre><code>list.get(i).setValue(obj);
</code></pre>

<p>where obj is a variable of type Object which could be an Integer, Float, etc.</p>

<p>Now there problem is that is the instance of C1 returned from the list (lets call it c1) was defined like this:</p>

<pre><code>C1&lt;Type1&gt;
</code></pre>

<p>Java will allow this:</p>

<pre><code>c1.setValue(val2);
</code></pre>

<p>where val2 is of type Type2 and Type2 is not equal to Type1 and is not even in the same class hierarchy (except Object ofc)!</p>

<p>EDIT: 
Forgot to ask the question :)
How do i make setValue "Type safe" when accessed the way I'm doing it above?</p>
