I was reading some sourcecode from Java libraries, and I am confused here;
This code is from Document.java in jaxb library, and ContentVisitor is an Interfac
It's valid. It's called Anonymous class. See here
We've already seen examples of the syntax for defining and instantiating an anonymous class. We can express that syntax more formally as:
new class-name ( [ argument-list ] ) { class-body }
or:
new interface-name () { class-body }
It is inline interface implementation.Here the idea is to have the compiler generate an anonymous class that implements the interface. Then for each method defined in the interface you can (optionally) provide a method with a suitable signature that will be used as the implementation of the interface's method.
It is the new Oxygene syntax, added to the language to allow Oxygene programmers to work with these interface-based events in much the same way as Java programmers do.
There's something called anonymous class in java http://www.java2s.com/Code/Java/Class/Anonymous-class.htm