@Retention(value=RUNTIME) @Target(value={METHOD,CONSTRUCTOR,FIELD}) public @interface Alias
The idiom for using Alias
is somewhat related to the Substitute
annotation, but
reversed; both are often used in combination. In both cases a separate class is used to declare
the aliased and/or substituted methods. In the substitution case occurrences of this
actually refer to the instance of the class being substituted. In the aliased case we pretend
that the class declaring the aliased method or field is an instance of the aliasee in order to
access its fields or invoke its methods. An alias is always called (method alias) or accessed
(field alias), whereas a substitution method is only implemented (usually not called directly).
In the body of a substitution method, aliases are often called or accessed.
The element can also be annotated with TargetElement
to specify additional properties.
See TargetClass
for an overview of the annotation system.
When aliasing *non-static* inner classes the constructors are passed a hidden argument which is the outer class. When writing an @Alias for a constructor of a *non-static* inner classes, you have to (a) explicitly declare that parameter, and (b) supply it in the calls.