Cast Object to specific Array in Java
<p>I'm having some trouble with this for some reason.</p>

<p>I have two java Objects, both of which can be anything, including primitive and non-primitive arrays.</p>

<p>I need to perform an equals check. </p>

<p>If they are arrays, then I have to check their contents instead of their runtime instance.</p>

<p>So for example, let's say I have a method as such:</p>

<pre><code>/**
     * Returns true if the two parameters are arrays, and they both contain
     * the same content.
     * @param aObject1 An object
     * @param aObject2 An object
     * @return
     */
    private boolean equalsArray( Object aObject1, Object aObject2 ) {
      if(aObject1==null){
        return false;
      }
      if(aObject2==null){
        return false;
      }
      if(!aObject1.getClass().isArray()){
        return false;
      }
      if(!aObject2.getClass().isArray()){
        return false;
      }
      //How do I check if the two arrays here contain the same objects
      //without knowledge of their type???

    }
</code></pre>

<p>Note that the arrays can be anything, and will most likely not be Object[], but rather Foo[] or Bar[].</p>

<p>Any suggestions? I can't do Array.equals(Object[],Object[]) because I can't cast to Object[].</p>
