title: Using File.listFiles with FileNameExtensionFilter
body: <p>I would like to get a list of files with a specific extension in a directory. In the API (Java 6), I see a method <code>File.listFiles(FileFilter)</code> which would do this.</p>
  
  <p>Since I need a specific extension, I created a <code>FileNameExtensionFilter</code>. However I get a compilation error when I use <code>listFiles</code> with this. I assumed that since <code>FileNameExtensionFilter implements FileFilter</code>, I should be able to do this. Code follows:</p>
  
  <pre><code>FileNameExtensionFilter filter = new FileNameExtensionFilter("text only","txt");
  String dir  = "/users/blah/dirname";
  File f[] = (new File(dir)).listFiles(filter);
  </code></pre>
  
  <p>The last line shows a compilation error:</p>
  
  <blockquote>
    <p>method listFiles(FileNameFilter) in type File is not applicable for arguments of type FileNameExtensionFilter</p>
  </blockquote>
  
  <p>I am trying to use <code>listFiles(FileFilter)</code>, not <code>listFiles(FileNameFilter)</code>. Why does the compiler not recognize this?</p>
  
  <p>This works if I write my own extension filter extending <code>FileFilter</code>. I would rather use <code>FileNameExtensionFilter</code> than write my own. What am I doing wrong?</p>