Java: Interface with new keyword how is that possible?

前端 未结 9 1508
抹茶落季
抹茶落季 2020-12-04 08:21

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

9条回答
  •  离开以前
    2020-12-04 09:19

    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.

提交回复
热议问题