title: Trying to downcast Object to File in java
body: <p>i wrote the next piece of code:</p>
  
  <pre><code>private ArrayList&lt;File&gt; filter() {
  
      ArrayList&lt;File&gt; result = _filters.get(0).buildTree(_dir.listFiles());
  
      for (int i=1; i&lt;_filters.size(); i++){
          File[] tempDir =  result.toArray();
          result = _filters.get(0).buildTree(tempDir);
      }
  
      return result;
  
  }
  </code></pre>
  
  <p>As you can see i have an ArrayList of FILE, then i use result.toArray which returns and Object[] array but it was File before, so why can't i downcast it back to File as i am trying to do in the 3rd line in the loop?
  i get the next error:</p>
  
  <pre><code>Exception in thread "main" java.lang.ClassCastException: [Ljava.lang.Object; cannot be cast to [Ljava.io.File;
  at oop.ex1.filescript.Command.filter(Command.java:50)
  at oop.ex1.filescript.Command.run(Command.java:28)
  </code></pre>
  
  <p>What are my options?</p>