title: Cast Object to Array
body: <p>So I have an Object which MIGHT be an array.  It can also be primitive, or a string. If it is an array, it can be an array of literally anything. </p>
  
  <p>I have no problem figuring out if it is an array but I can't seem to cast it into anything that I can iterate through to get the values out of.</p>
  
  <pre><code>// o is an object and clazz is the class of the o
  if (clazz == Array.class) {
              Class ofArray = o.getClass().getComponentType();
              String arrayType = ofArray.getName(); // 'Double' for my test case
              //ERROR: [D cannot be cast to [Ljava.lang.Object 
              Object[] objects = (Object[]) o; 
      }
  </code></pre>
  
  <p>My background is in ruby and php (where it would just work) and the static typing is messing with my head. Any ideas?</p>
  
  <p><strong>EDIT:</strong></p>
  
  <p>This throws the error</p>
  
  <pre><code>[D cannot be cast to [Ljava.lang.Object.
  </code></pre>
  
  <p>What am I missing?</p>
  
  <pre><code>if (o.getClass().isArray()) {
      Object[] objects = (Object[]) o;  
  }
  </code></pre>