title: Instantiable anonymous Java Intefrace:Is it possible or am I wrong?
body: <p>In the Java7 API reference(<a href="http://docs.oracle.com/javase/7/docs/api/" rel="nofollow">Java API 7</a>) there's a function <code>list()</code> of <code>File</code> class that has the signature:</p>
  
  <pre class="lang-java prettyprint-override"><code>public String[] list(FilenameFilter filter)
  </code></pre>
  
  <p>where <em><code>FilenameFilter</code></em> is an interface. Suppose the use of this function in a program is something like below:</p>
  
  <pre class="lang-java prettyprint-override"><code>String[] list = new File(directory).list(new FilenameFilter() {
  
       @Override
       public boolean accept(File f, String s) 
       {
          return s.endsWith(".java"); 
       } 
  });
  </code></pre>
  
  <p>As you can see we are instantiating an interface anonymously.</p>
  
  <p>Please correct me if I'm wrong but is instantiating an interface valid in Java?</p>
  
  <p>The reason I'm asking this because I thought interfaces are not instantiable(because interfaces don't have constructors) and for using an interface you have to implement that interface by a class. Then how's that possible that we are instantiating an interface without implementing by a class here?</p>
  
  <p>Can anyone kindly help me find the error in my logic?</p>