Top Description Inners Methods
com.google.auto.value

public @Interface AutoValue

extends Annotation
Annotations
@Retention:CLASS
@Target:TYPE
Imports
java.lang.annotation.Annotation, .ElementType, .Retention, .RetentionPolicy, .Target

Specifies that AutoValue should generate an implementation class for the annotated abstract class, implementing the standard Object methods like equals to have conventional value semantics. A simple example:

  @AutoValue
  abstract class Person {
    static Person create(String name, int id) {
      return new AutoValue_Person(name, id);
    }

    abstract String name();
    abstract int id();
  }
Authors
Éamonn McManus, Kevin Bourrillion
See Also
AutoValue User's Guide

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static @interface
AutoValue.Builder

Specifies that AutoValue should generate an implementation of the annotated class or interface, to serve as a builder for the value-type class it is nested within.

public static @interface
AutoValue.CopyAnnotations

Specifies that AutoValue should copy any annotations from the annotated element to the generated class.

Method Summary

Inherited from java.lang.annotation.Annotation:
annotationTypeequalshashCodetoString
com.google.auto.value back to summary

public @Interface AutoValue.Builder

extends Annotation
Annotations
@Retention:CLASS
@Target:TYPE

Specifies that AutoValue should generate an implementation of the annotated class or interface, to serve as a builder for the value-type class it is nested within. As a simple example, here is an alternative way to write the Person class mentioned in the AutoValue example:

  @AutoValue
  abstract class Person {
    static Builder builder() {
      return new AutoValue_Person.Builder();
    }

    abstract String name();
    abstract int id();

    @AutoValue.Builder
    interface Builder {
      Builder name(String x);
      Builder id(int x);
      Person build();
    }
  }
Author
Éamonn McManus

Method Summary

Inherited from java.lang.annotation.Annotation:
annotationTypeequalshashCodetoString
com.google.auto.value back to summary

public @Interface AutoValue.CopyAnnotations

extends Annotation
Annotations
@Retention:CLASS
@Target:TYPE, METHOD

Specifies that AutoValue should copy any annotations from the annotated element to the generated class. This annotation supports classes and methods.

The following annotations are excluded:

  1. AutoValue and its nested annotations;
  2. any annotation appearing in the AutoValue.CopyAnnotations#exclude field;
  3. any class annotation which is itself annotated with the java.lang.annotation.Inherited meta-annotation.

For historical reasons, annotations are always copied from an @AutoValue property method to its implementation, unless @CopyAnnotations is present and explicitly excludes that annotation. But annotations are not copied from the @AutoValue class itself to its implementation unless @CopyAnnotations is present.

If you want to copy annotations from your @AutoValue-annotated class's methods to the generated fields in the AutoValue_... implementation, annotate your method with @AutoValue.CopyAnnotations. For example, if Example.java is:


  @Immutable
  @AutoValue
  abstract class Example {
    @CopyAnnotations
    @SuppressWarnings("Immutable") // justification ...
    abstract Object getObject();
    // other details ...
  }

Then AutoValue will generate the following AutoValue_Example.java:


  final class AutoValue_Example extends Example {
    @SuppressWarnings("Immutable")
    private final Object object;

    @SuppressWarnings("Immutable")
    @Override
    Object getObject() {
      return object;
    }

    // other details ...
  }

When the type of an @AutoValue property method has annotations, those are part of the type, so by default they are copied to the implementation of the method. But if a type annotation is mentioned in exclude then it is not copied.

For example, suppose @Confidential is a TYPE_USE annotation:


  @AutoValue
  abstract class Person {
    static Person create(@Confidential String name, int id) {
      return new AutoValue_Person(name, id);
    }

    abstract @Confidential String name();
    abstract int id();
  }
Then the implementation of the name() method will also have return type @Confidential String. But if name() were written like this...

    @AutoValue.CopyAnnotations(exclude = Confidential.class)
    abstract @Confidential String name();

...then the implementation of name() would have return type String without the annotation.

Author
Carmi Grushko

Method Summary

Modifier and TypeMethod and Description
public Class<? extends Annotation>[]
Inherited from java.lang.annotation.Annotation:
annotationTypeequalshashCodetoString

Method Detail

excludeback to summary
public Class<? extends Annotation>[] exclude()