The line is wrong. It should have a space between "new" and "Foo":
new Foo() { public int bar(){ return 1; } }
This creates an instance of an anonymous type which implements Foo
. See Java in a Nutshell: Anonymous Classes (section 3.12.3 covers the syntax).
Anonymous classes are often used extensively with event listeners. See Swing Trail: Inner Classes and Anonymous Inner Classes (but ignore the Inner Classes discussed at the top of that section ;-)
Happy coding.
For comment:
Line 14 is the start of the method call for fubar
(which is defined above as public int fubar(Foo foo)
). Note that new ...
is an expression (anonymous type or not) and the result of that expression (a new object) is passed as an argument to fubar
. The formatting is mostly arbitrary -- it could have been all on one line. Consider this code:
Foo aNewFoo = new Foo() { ... };
fuubar(aNewFoo);
Hope that clears things up.