title: Strange java.lang.ClassCastException when using [] call
body: <p>I'm using LibDGX library for my game. And i faced common exception <code>ClassCastException</code>, but it occurs in strange case.</p>
  
  <p>I'm using <a href="https://www.google.ru/url?sa=t&amp;rct=j&amp;q=&amp;esrc=s&amp;source=web&amp;cd=2&amp;ved=0ahUKEwjosLKj6ubXAhXGCJoKHQ4RBo0QFggzMAE&amp;url=https%3A%2F%2Flibgdx.badlogicgames.com%2Fnightlies%2Fdocs%2Fapi%2Fcom%2Fbadlogic%2Fgdx%2Fgraphics%2Fg2d%2FAnimation.html&amp;usg=AOvVaw1X84E6QtOoKNhHovt_jweG" rel="nofollow noreferrer">Animation</a> class from LibGDX library.  </p>
  
  <p>I'm getting error on this line <strong>only if i am using <code>[]</code> operation.</strong></p>
  
  <pre><code>val tex = animation.keyFrames[0]
  </code></pre>
  
  <p>If i change it to <code>get()</code> <strong>error disappears</strong>.</p>
  
  <pre><code>tex = animation.keyFrames.get(0)
  </code></pre>
  
  <p>Here is full method. I simplified example.</p>
  
  <pre><code>override fun create() {
  
  
      val frames = Array&lt;TextureRegion&gt;()
      frames.add(TextureRegion(Texture("badlogic.jpg")))
  
      val animation = Animation(frames)
  
      val tex1 = animation.keyFrames.get(0)  // Compiles
  
      val tex = animation.keyFrames[0]  // error - [Ljava.lang.Object; cannot be cast to [Lcom.badlogic.gdx.graphics.g2d.TextureRegion;
  
  
  }
  </code></pre>
  
  <p>Strange, isn't it?</p>
  
  <p>Here is Animation class that i used to minimise other error reasons. It is the same as in LibGDX api.</p>
  
  <pre><code>    public class Animation&lt;T&gt; {
  
      T[] keyFrames;
      private float frameDuration;
  
  
      public Animation (float frameDuration, Array&lt;? extends T&gt; keyFrames) {
          this.frameDuration = frameDuration;
  
          Class arrayType = keyFrames.items.getClass().getComponentType();
          T[] frames = (T[]) ArrayReflection.newInstance(arrayType, keyFrames.size);
          for (int i = 0, n = keyFrames.size; i &lt; n; i++) {
              frames[i] = keyFrames.get(i);
          }
  
          setKeyFrames(frames);
      }
  
      protected void setKeyFrames (T... keyFrames) {
          this.keyFrames = keyFrames;
      }
  }
  </code></pre>
  
  <p>I also noticed that error <strong>disappears</strong> if i use <code>Array.with</code> construction instead of creating <code>Array&lt;TextureRegion&gt;</code> I mean LibGDX <a href="https://libgdx.badlogicgames.com/nightlies/docs/api/com/badlogic/gdx/utils/Array.html" rel="nofollow noreferrer">Array</a> not from Kotlin.</p>
  
  <pre><code>val animation = Animation(Array.with(TextureRegion(Texture("badlogic.jpg"))))
  </code></pre>
  
  <p>Could you tell me the reason why this occurs or it is possible a bug? </p>