title: Anonymous class definition based on interface... maybe?
body: <p>I saw this Java snippet in the book <em>Spring in Action</em>, but I'm not familiar with the language construct.</p>
  
  <pre><code>new RowMapper() {
    public Object mapRow() throws SQLException, DataAccessException {
      Motorist motorist = new Motorist();
      motorist.setId(rs.getInt(1));
      motorist.setEmail(rs.getString(2));
      motorist.setPassword(rs.getString(3));
      motorist.setFirstName(rs.getString(4));
      motorist.setLastName(rs.getString(5));
      return motorist;
    }
  }
  </code></pre>
  
  <p>According the <a href="http://static.springsource.org/spring/docs/1.2.x/api/org/springframework/jdbc/core/RowMapper.html" rel="nofollow noreferrer">Spring documentation</a>, RowMapper is an interface.  It looks to me like an anonymous class definition based on the RowMapper interface.  The <code>new</code> keyword is a little confusing, making me wonder if this also creates one instance of the anonymous class.  I would guess yes, because if the class has no name, how will you ever create an instance <em>after</em> the line that defines it?</p>
  
  <p>Can anyone confirm my guesses that:</p>
  
  <ul>
  <li>this is an anonymous class definition based on the RowMapper interface, and</li>
  <li>it creates a single instance of that class?</li>
  </ul>