title: Why does Java allow type-unsafe Array assignments?
body: <p>Generally, Java can be considered as a type-safe language. I know that there are some flaws with generics, but I recently came across a Problem I never had before.
  To break it down:</p>
  
  <pre><code>Object[] objects = new Integer[10];
  objects[0] = "Hello World";
  </code></pre>
  
  <p>will NOT result in a compile-time error as expected. I would assume that the declaration of an Array of <code>Object</code> will disallow to point to to an array of something else. In Generics I'm not allowed to make such weird things like:</p>
  
  <pre><code>ArrayList&lt;Object&gt; objs = new ArrayList&lt;Integer&gt;
  </code></pre>
  
  <p>and if I try to kind of trick Java into doing something with</p>
  
  <pre><code>ArrayList&lt;? extends Object&gt; objects = new ArrayList&lt;Integer&gt;
  </code></pre>
  
  <p>I'm allowed to declare it, but I can only add Objects of type <code>null</code>. </p>
  
  <p>Why doesn't Java prevent the declaration of such weired arrays?</p>