Annotation Type Virtual


@Documented @Retention(RUNTIME) @Target(METHOD) public @interface Virtual
Marks a public trait static method as virtual: trait-body calls to this method dispatch through the implementing class at runtime, so a same-signature static method declared on the implementing class overrides the trait's default.

This is the opt-in counterpart to the default declarer-bound dispatch for trait static methods, where trait-body calls invoke the trait's own copy regardless of any same-named static on the implementer. The opt-in restores the per-implementer override pattern used by Grails' Validateable.defaultNullable() and similar framework hooks.

The marker is per-callee, not per-caller: it changes how trait code invokes the annotated method, regardless of which method inside the trait does the calling.

Valid only on public, non-abstract static trait methods. Applying it to an instance method, a private method, an abstract method, or anything outside a trait is a compile-time error.

Since:
5.0.7