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
You actually have just provided the implementation of this interface in an anonymous way. This is quite common and of course possible. Have a look here for more information.