title: Casting "with" Interface
body: <pre><code>interface I{}
  class A implements I{}
  class B{}
  </code></pre>
  
  <p>First:</p>
  
  <pre><code>I[] arr = new A[10];
  arr[0] = (I) new B(); // will produce ClassCastException at runtime
  </code></pre>
  
  <p>Second:
  wherein if I use concrete class</p>
  
  <pre><code>I[] arr = new A[10];
  arr[0] = (A) new B(); // will produce compile-time error
  </code></pre>
  
  <p>What's the difference if in my first example,<code>(I) new B()</code>, the java compiler should produce compile-error as well?</p>
  
  <p>Isn't it that the java compiler should be able to distinguish that it is also an "inconvertible type"? Especially when the new operator comes immediately?</p>
  
  <p>Is there any instance/chance that it will be possible that creating that new instance of B could produce a 
  convertible type of type I?</p>
  
  <p>I know at some point, that the Java compiler should not immediately say that it is a compiler error, like when you do this:</p>
  
  <pre><code>I i = (I) getContent(); // wherein getContent() will return a type of Object
  </code></pre>
  
  <p><strong>Edit:</strong></p>
  
  <p>Let me clarify this question why it is not a possible duplicate of this: <a href="https://stackoverflow.com/questions/16347252/cast-reference-of-known-type-to-an-interface-outside-of-types-hierarchy">Cast reference of known type to an interface outside of type&#39;s hierarchy</a></p>
  
  <p>The intention of this question is not because I am not aware of what will be the result of or what is something wrong with something, etc. </p>
  
  <p>I just want to know a "more detailed explanation in a technical way" of why does the JVM behave that way or why does Java came up with that kind of decision of not making that kind of scenario a <em>compile-time</em> error. </p>
  
  <p>As what we all know, it is always better to find "problematic code" at compile-time rather than at run-time.</p>
  
  <p>Another thing, the answer I am looking for was found here on this thread not on those "duplicates?".</p>