How RowMapper can be an Anonymous Class
java, spring
Solution
Anonymous class `new Something() {...}` is not an instance of `Something`. Instead, it's a subclass/implementation of `Something`. And so, it's perfectly valid and useful to derive anonymous classes from interfaces.
Problem
I was reading through Spring in Action and found something like this could anyone explain how we have used RowMapper as an Anonymous class if it is an Interface as per RowMapper documentation. ``` public Employee getEmployeeById(long id) { return jdbcTemplate.queryForObject( "select id, firstname, lastname, salary " + "from employee where id=?", new RowMapper<Employee>() { public Employee mapRow(ResultSet rs, int rowNum) throws SQLException { Employee employee = new Employee(); employee.setId(rs.getLong("id")); employee.setFirstName(rs.getString("firstname")); employee.setLastName(rs.getString("lastname")); employee.setSalary(rs.getBigDecimal("salary")); return employee; } }, id); } ```