title: Seeking explanation for Auto-Casting
body: <p>So I just spent around an hour trying to unveil and resolve a very strange bug, one that I have never seen before.</p>
  
  <p><strong>I am more or less asking for potential causes of this seeming random cast from enum to String rather than "please fix my code for me"</strong>.</p>
  
  <p>The gist of the problem is as follows:</p>
  
  <p>I have an interface, call it <code>IFoo</code>, within this interface, it has a static enum, called <code>Bar</code>:</p>
  
  <pre><code>public interface IFoo {
    static enum Bar{
      A,
      B,
      C,
    }
  
    Bar doGetBar();
  }
  </code></pre>
  
  <p>I of course have a <code>Foo</code> class that implements <code>IFoo</code>.</p>
  
  <pre><code>public class Foo implements IFoo{
    public Bar getBar(){
      return Bar.A; // for example
    }
  }
  </code></pre>
  
  <p>Somewhere else, I have an object array called</p>
  
  <pre><code>Object[] result;
  </code></pre>
  
  <p>And a helper method that returns an array of <code>Object</code>s, holding results from the <code>getBar()</code>method, call it</p>
  
  <pre><code>public Object[] getBars()
  </code></pre>
  
  <p>Now, when I do</p>
  
  <pre><code>result = getBars();
  </code></pre>
  
  <p><code>result</code> magically holds <code>String</code>s instead of <code>Bar</code>s, the values of the strings are the implementation class of the outer class (not really an outer class, more of a wrapper class?)  of <code>Bar</code>, i.e. "Foo".</p>
  
  <p>Could someone possibly explain to me how this is possible?</p>
  
  <p>Some leads: 
  1. results were holding strings before the assignment.
  2. the static enum inside IFoo is questionable, it was non-static, but it caused <code>ClassCastException</code>s when I tried to cast it to IFoo.Bar from Foo.Bar (or something along these lines).</p>