tags:

views:

61

answers:

4

Just reading up on spring's data access, and it has something like this:

jdbcTemplate.query(someSql,
                  new Object[] { 1 },
                  new RowMapper() {

                     public Object mapRow(ResultSet rs, int rowNum) ...
                         Blah blah = new Blah();
                         blah.setId( rs.getInt(1));


                  }

I'm referring to the public Object mapRow part.

is this a inline class, or a callback? (or something else)

+2  A: 

It is a method on the anonymous inner class you created based on the RowMapper class/interface.

It could also be called a callback (in some general sense of the word) if it is passed somewhere and called in response to some kind of event occurring.

fd
+3  A: 

It's a callback/upcall implemented with an anonymous inner class. "Inline class" is some made up terminology (where did it come from??).

The new version of closures that should appear in JDK7 should make this sort of thing much less verbose.

The idiom is known as Execute Around.

Tom Hawtin - tackline
A: 

I believe that would be defined as an inline class being passed to another object. A callback class would require some function that the original object to which it was passed could access and...well...call back.

Topher Fangio
+1  A: 

That's an anonymous inner class implementing Spring's RowMapper interface.

Jeff Sternal