title: Java upcasting in container
body: <p>I have two classes parent and child and child extends parent.</p>
  
  <pre><code>Parent parent = new Child();
  </code></pre>
  
  <p>Works as expected but the confusion happens when the object is in an container like so.</p>
  
  <pre><code>Vector&lt;Parent&gt; vp = new Vector&lt;Child&gt;();
  </code></pre>
  
  <p>This gives the error: </p>
  
  <pre><code>incompatible types: Vector&lt;Child&gt; cannot be converted to Vector&lt;Parent&gt;
  </code></pre>
  
  <p>So my question is does the container prevent the implicit typecasting that occurs when we do </p>
  
  <pre><code>parent = new Child();
  </code></pre>