@Target(value=METHOD) @Retention(value=SOURCE) public @interface AutoAnnotation
Annotation
, in particular as regards equals
and
hashCode
. These instances behave essentially the same as instances
returned by AnnotatedElement.getAnnotation(java.lang.Class<T>)
.
For example, suppose you have an annotation like this:
package com.google.inject.name; public @interface Named { String value(); }
You could write a method like this to construct implementations of the interface:
package com.example; public class Names { @AutoAnnotation public static Named named(String value) { return new AutoAnnotation_Names_named(value); } }
Because the annotated method is called Names.named
, the generated class is called
AutoAnnotation_Names_named
in the same package. If the annotated method were in a nested
class, for example Outer.Names.named
, then the generated class would be called
AutoAnnotation_Outer_Names_named
. The generated class is package-private and it is not
expected that it will be referenced outside the @AutoAnnotation
method.
The names and types of the parameters in the annotated method must be the same as the names and types of the annotation elements, except that elements which have default values can be omitted. The parameters do not need to be in any particular order.
The annotated method does not need to be public. It can have any visibility, including private. This means the method can be a private implementation called by a public method with a different API, for example using a builder.
It is a compile-time error if more than one method with the same name in the same class is
annotated @AutoAnnotation
.
The constructor of the generated class has the same parameters as the @AutoAnnotation
method. It will throw NullPointerException
if any parameter is null. In order to
guarantee that the constructed object is immutable, the constructor will clone each array
parameter corresponding to an array-valued annotation member, and the implementation of each such
member will also return a clone of the array.
Copyright © 2016 Google, Inc.. All Rights Reserved.