xref: /aosp_15_r20/external/auto/value/userguide/index.md (revision 1c2bbba85eccddce6de79cbbf1645fda32e723f0)
1*1c2bbba8SAndroid Build Coastguard Worker# AutoValue
2*1c2bbba8SAndroid Build Coastguard Worker
3*1c2bbba8SAndroid Build Coastguard Worker
4*1c2bbba8SAndroid Build Coastguard Worker*Generated immutable value classes for Java 7+* <br />
5*1c2bbba8SAndroid Build Coastguard Worker***Éamonn McManus, Kevin Bourrillion*** <br />
6*1c2bbba8SAndroid Build Coastguard Worker**Google, Inc.**
7*1c2bbba8SAndroid Build Coastguard Worker
8*1c2bbba8SAndroid Build Coastguard Worker> "AutoValue is a great tool for eliminating the drudgery of writing mundane
9*1c2bbba8SAndroid Build Coastguard Worker> value classes in Java. It encapsulates much of the advice in Effective Java
10*1c2bbba8SAndroid Build Coastguard Worker> Chapter 2, and frees you to concentrate on the more interesting aspects of
11*1c2bbba8SAndroid Build Coastguard Worker> your program. The resulting program is likely to be shorter, clearer, and
12*1c2bbba8SAndroid Build Coastguard Worker> freer of bugs. Two thumbs up."
13*1c2bbba8SAndroid Build Coastguard Worker>
14*1c2bbba8SAndroid Build Coastguard Worker> -- *Joshua Bloch, author, Effective Java*
15*1c2bbba8SAndroid Build Coastguard Worker
16*1c2bbba8SAndroid Build Coastguard Worker## <a name="background"></a>Background
17*1c2bbba8SAndroid Build Coastguard Worker
18*1c2bbba8SAndroid Build Coastguard Worker**Value classes** are extremely common in Java projects. These are classes for
19*1c2bbba8SAndroid Build Coastguard Workerwhich you want to treat any two instances with suitably equal field values as
20*1c2bbba8SAndroid Build Coastguard Workerinterchangeable. That's right: we're talking about those classes where you wind
21*1c2bbba8SAndroid Build Coastguard Workerup implementing `equals`, `hashCode` and `toString` in a bloated, repetitive,
22*1c2bbba8SAndroid Build Coastguard Workerformulaic yet error-prone fashion.
23*1c2bbba8SAndroid Build Coastguard Worker
24*1c2bbba8SAndroid Build Coastguard WorkerWriting these methods the first time is not too bad, with the aid of a few
25*1c2bbba8SAndroid Build Coastguard Workerhelper methods and IDE templates. But once written they continue to burden
26*1c2bbba8SAndroid Build Coastguard Workerreviewers, editors and future readers. Their wide expanses of boilerplate
27*1c2bbba8SAndroid Build Coastguard Workersharply decrease the signal-to-noise ratio of your code... and they love to
28*1c2bbba8SAndroid Build Coastguard Workerharbor hard-to-spot bugs.
29*1c2bbba8SAndroid Build Coastguard Worker
30*1c2bbba8SAndroid Build Coastguard WorkerAutoValue provides an easier way to create immutable value classes, with a lot
31*1c2bbba8SAndroid Build Coastguard Workerless code and less room for error, while **not restricting your freedom** to
32*1c2bbba8SAndroid Build Coastguard Workercode almost any aspect of your class exactly the way you want it.
33*1c2bbba8SAndroid Build Coastguard Worker
34*1c2bbba8SAndroid Build Coastguard Worker**Note**: If you are using Kotlin then its
35*1c2bbba8SAndroid Build Coastguard Worker[data classes](https://kotlinlang.org/docs/data-classes.html) are usually more
36*1c2bbba8SAndroid Build Coastguard Workerappropriate than AutoValue. Likewise, if you are using a version of Java that
37*1c2bbba8SAndroid Build Coastguard Workerhas [records](https://docs.oracle.com/en/java/javase/17/language/records.html),
38*1c2bbba8SAndroid Build Coastguard Workerthen those are usually more appropriate. For a detailed comparison of AutoValue
39*1c2bbba8SAndroid Build Coastguard Workerand records, including information on how to migrate from one to the other, see
40*1c2bbba8SAndroid Build Coastguard Worker[here](records.md).<br>
41*1c2bbba8SAndroid Build Coastguard WorkerYou can still use [AutoBuilder](autobuilder.md) to make builders for data
42*1c2bbba8SAndroid Build Coastguard Workerclasses or records.
43*1c2bbba8SAndroid Build Coastguard Worker
44*1c2bbba8SAndroid Build Coastguard WorkerThis page will walk you through how to use AutoValue. Looking for a little more
45*1c2bbba8SAndroid Build Coastguard Workerpersuasion? Please see [Why AutoValue?](why.md).
46*1c2bbba8SAndroid Build Coastguard Worker
47*1c2bbba8SAndroid Build Coastguard Worker## <a name="howto"></a>How to use AutoValue
48*1c2bbba8SAndroid Build Coastguard Worker
49*1c2bbba8SAndroid Build Coastguard WorkerThe AutoValue concept is extremely simple: **You write an abstract class, and
50*1c2bbba8SAndroid Build Coastguard WorkerAutoValue implements it.** That is all there is to it; there is literally *no*
51*1c2bbba8SAndroid Build Coastguard Workerconfiguration.
52*1c2bbba8SAndroid Build Coastguard Worker
53*1c2bbba8SAndroid Build Coastguard Worker**Note:** Below, we will illustrate an AutoValue class *without* a generated
54*1c2bbba8SAndroid Build Coastguard Workerbuilder class. If you're more interested in the builder support, continue
55*1c2bbba8SAndroid Build Coastguard Workerreading at [AutoValue with Builders](builders.md) instead.
56*1c2bbba8SAndroid Build Coastguard Worker
57*1c2bbba8SAndroid Build Coastguard Worker### <a name="example_java"></a>In your value class
58*1c2bbba8SAndroid Build Coastguard Worker
59*1c2bbba8SAndroid Build Coastguard WorkerCreate your value class as an *abstract* class, with an abstract accessor method
60*1c2bbba8SAndroid Build Coastguard Workerfor each desired property, and bearing the `@AutoValue` annotation.
61*1c2bbba8SAndroid Build Coastguard Worker
62*1c2bbba8SAndroid Build Coastguard Worker```java
63*1c2bbba8SAndroid Build Coastguard Workerimport com.google.auto.value.AutoValue;
64*1c2bbba8SAndroid Build Coastguard Worker
65*1c2bbba8SAndroid Build Coastguard Worker@AutoValue
66*1c2bbba8SAndroid Build Coastguard Workerabstract class Animal {
67*1c2bbba8SAndroid Build Coastguard Worker  static Animal create(String name, int numberOfLegs) {
68*1c2bbba8SAndroid Build Coastguard Worker    return new AutoValue_Animal(name, numberOfLegs);
69*1c2bbba8SAndroid Build Coastguard Worker  }
70*1c2bbba8SAndroid Build Coastguard Worker
71*1c2bbba8SAndroid Build Coastguard Worker  abstract String name();
72*1c2bbba8SAndroid Build Coastguard Worker  abstract int numberOfLegs();
73*1c2bbba8SAndroid Build Coastguard Worker}
74*1c2bbba8SAndroid Build Coastguard Worker```
75*1c2bbba8SAndroid Build Coastguard Worker
76*1c2bbba8SAndroid Build Coastguard WorkerThe constructor parameters correspond, in order, to the abstract accessor
77*1c2bbba8SAndroid Build Coastguard Workermethods.
78*1c2bbba8SAndroid Build Coastguard Worker
79*1c2bbba8SAndroid Build Coastguard Worker**For a nested class**, see ["How do I use AutoValue with a nested class"](howto.md#nested).
80*1c2bbba8SAndroid Build Coastguard Worker
81*1c2bbba8SAndroid Build Coastguard WorkerNote that in real life, some classes and methods would presumably be public and
82*1c2bbba8SAndroid Build Coastguard Workerhave Javadoc. We're leaving these off in the User Guide only to keep the
83*1c2bbba8SAndroid Build Coastguard Workerexamples short and simple.
84*1c2bbba8SAndroid Build Coastguard Worker
85*1c2bbba8SAndroid Build Coastguard Worker### With Maven
86*1c2bbba8SAndroid Build Coastguard Worker
87*1c2bbba8SAndroid Build Coastguard WorkerYou will need `auto-value-annotations-${auto-value.version}.jar` in your
88*1c2bbba8SAndroid Build Coastguard Workercompile-time classpath, and you will need `auto-value-${auto-value.version}.jar`
89*1c2bbba8SAndroid Build Coastguard Workerin your annotation-processor classpath.
90*1c2bbba8SAndroid Build Coastguard Worker
91*1c2bbba8SAndroid Build Coastguard WorkerFor `auto-value-annotations`, you can write this in `pom.xml`:
92*1c2bbba8SAndroid Build Coastguard Worker
93*1c2bbba8SAndroid Build Coastguard Worker```xml
94*1c2bbba8SAndroid Build Coastguard Worker<dependencies>
95*1c2bbba8SAndroid Build Coastguard Worker  <dependency>
96*1c2bbba8SAndroid Build Coastguard Worker    <groupId>com.google.auto.value</groupId>
97*1c2bbba8SAndroid Build Coastguard Worker    <artifactId>auto-value-annotations</artifactId>
98*1c2bbba8SAndroid Build Coastguard Worker    <version>${auto-value.version}</version>
99*1c2bbba8SAndroid Build Coastguard Worker  </dependency>
100*1c2bbba8SAndroid Build Coastguard Worker</dependencies>
101*1c2bbba8SAndroid Build Coastguard Worker```
102*1c2bbba8SAndroid Build Coastguard Worker
103*1c2bbba8SAndroid Build Coastguard WorkerSome AutoValue annotations have CLASS retention. This is mostly of use for
104*1c2bbba8SAndroid Build Coastguard Workercompile-time tools, such as AutoValue itself. If you are creating
105*1c2bbba8SAndroid Build Coastguard Workera library, the end user rarely needs to know the original AutoValue annotations.
106*1c2bbba8SAndroid Build Coastguard WorkerIn that case, you can set the scope to `provided`, so that the user of your
107*1c2bbba8SAndroid Build Coastguard Workerlibrary does not have `auto-value-annotations` as a transitive dependency.
108*1c2bbba8SAndroid Build Coastguard Worker
109*1c2bbba8SAndroid Build Coastguard Worker```xml
110*1c2bbba8SAndroid Build Coastguard Worker<dependencies>
111*1c2bbba8SAndroid Build Coastguard Worker  <dependency>
112*1c2bbba8SAndroid Build Coastguard Worker    <groupId>com.google.auto.value</groupId>
113*1c2bbba8SAndroid Build Coastguard Worker    <artifactId>auto-value-annotations</artifactId>
114*1c2bbba8SAndroid Build Coastguard Worker    <version>${auto-value.version}</version>
115*1c2bbba8SAndroid Build Coastguard Worker    <scope>provided</scope>
116*1c2bbba8SAndroid Build Coastguard Worker  </dependency>
117*1c2bbba8SAndroid Build Coastguard Worker</dependencies>
118*1c2bbba8SAndroid Build Coastguard Worker```
119*1c2bbba8SAndroid Build Coastguard Worker
120*1c2bbba8SAndroid Build Coastguard WorkerFor `auto-value` (the annotation processor), you can write this:
121*1c2bbba8SAndroid Build Coastguard Worker
122*1c2bbba8SAndroid Build Coastguard Worker```xml
123*1c2bbba8SAndroid Build Coastguard Worker<build>
124*1c2bbba8SAndroid Build Coastguard Worker  <plugins>
125*1c2bbba8SAndroid Build Coastguard Worker    <plugin>
126*1c2bbba8SAndroid Build Coastguard Worker      <artifactId>maven-compiler-plugin</artifactId>
127*1c2bbba8SAndroid Build Coastguard Worker      <configuration>
128*1c2bbba8SAndroid Build Coastguard Worker        <annotationProcessorPaths>
129*1c2bbba8SAndroid Build Coastguard Worker          <path>
130*1c2bbba8SAndroid Build Coastguard Worker            <groupId>com.google.auto.value</groupId>
131*1c2bbba8SAndroid Build Coastguard Worker            <artifactId>auto-value</artifactId>
132*1c2bbba8SAndroid Build Coastguard Worker            <version>${auto-value.version}</version>
133*1c2bbba8SAndroid Build Coastguard Worker          </path>
134*1c2bbba8SAndroid Build Coastguard Worker        </annotationProcessorPaths>
135*1c2bbba8SAndroid Build Coastguard Worker      </configuration>
136*1c2bbba8SAndroid Build Coastguard Worker    </plugin>
137*1c2bbba8SAndroid Build Coastguard Worker  </plugins>
138*1c2bbba8SAndroid Build Coastguard Worker</build>
139*1c2bbba8SAndroid Build Coastguard Worker```
140*1c2bbba8SAndroid Build Coastguard Worker
141*1c2bbba8SAndroid Build Coastguard WorkerAlternatively, you can include the processor itself in your compile-time
142*1c2bbba8SAndroid Build Coastguard Workerclasspath. Doing so may pull unnecessary classes into your runtime classpath.
143*1c2bbba8SAndroid Build Coastguard Worker
144*1c2bbba8SAndroid Build Coastguard Worker```xml
145*1c2bbba8SAndroid Build Coastguard Worker<dependencies>
146*1c2bbba8SAndroid Build Coastguard Worker  <dependency>
147*1c2bbba8SAndroid Build Coastguard Worker    <groupId>com.google.auto.value</groupId>
148*1c2bbba8SAndroid Build Coastguard Worker    <artifactId>auto-value</artifactId>
149*1c2bbba8SAndroid Build Coastguard Worker    <version>${auto-value.version}</version>
150*1c2bbba8SAndroid Build Coastguard Worker    <optional>true</optional>
151*1c2bbba8SAndroid Build Coastguard Worker  </dependency>
152*1c2bbba8SAndroid Build Coastguard Worker</dependencies>
153*1c2bbba8SAndroid Build Coastguard Worker```
154*1c2bbba8SAndroid Build Coastguard Worker
155*1c2bbba8SAndroid Build Coastguard Worker### With Gradle
156*1c2bbba8SAndroid Build Coastguard Worker
157*1c2bbba8SAndroid Build Coastguard WorkerGradle users can declare the dependencies in their `build.gradle` script:
158*1c2bbba8SAndroid Build Coastguard Worker
159*1c2bbba8SAndroid Build Coastguard Worker```groovy
160*1c2bbba8SAndroid Build Coastguard Workerdependencies {
161*1c2bbba8SAndroid Build Coastguard Worker  compileOnly         "com.google.auto.value:auto-value-annotations:${autoValueVersion}"
162*1c2bbba8SAndroid Build Coastguard Worker  annotationProcessor "com.google.auto.value:auto-value:${autoValueVersion}"
163*1c2bbba8SAndroid Build Coastguard Worker}
164*1c2bbba8SAndroid Build Coastguard Worker```
165*1c2bbba8SAndroid Build Coastguard Worker
166*1c2bbba8SAndroid Build Coastguard WorkerNote: For java-library projects, use `compileOnlyApi` (or `api` for Gradle
167*1c2bbba8SAndroid Build Coastguard Workerversions prior to 6.7) instead of `compileOnly`. For Android projects, use `api`
168*1c2bbba8SAndroid Build Coastguard Workerinstead of `compileOnly`. If you are using a version prior to 4.6, you must
169*1c2bbba8SAndroid Build Coastguard Workerapply an annotation processing plugin
170*1c2bbba8SAndroid Build Coastguard Worker[as described in these instructions][tbroyer-apt].
171*1c2bbba8SAndroid Build Coastguard Worker
172*1c2bbba8SAndroid Build Coastguard Worker[tbroyer-apt]: https://plugins.gradle.org/plugin/net.ltgt.apt
173*1c2bbba8SAndroid Build Coastguard Worker
174*1c2bbba8SAndroid Build Coastguard Worker### <a name="usage"></a>Usage
175*1c2bbba8SAndroid Build Coastguard Worker
176*1c2bbba8SAndroid Build Coastguard WorkerYour choice to use AutoValue is essentially *API-invisible*. This means that, to
177*1c2bbba8SAndroid Build Coastguard Workerthe consumer of your class, your class looks and functions like any other. The
178*1c2bbba8SAndroid Build Coastguard Workersimple test below illustrates that behavior. Note that in real life, you would
179*1c2bbba8SAndroid Build Coastguard Workerwrite tests that actually *do something interesting* with the object, instead of
180*1c2bbba8SAndroid Build Coastguard Workeronly checking field values going in and out.
181*1c2bbba8SAndroid Build Coastguard Worker
182*1c2bbba8SAndroid Build Coastguard Worker```java
183*1c2bbba8SAndroid Build Coastguard Workerpublic void testAnimal() {
184*1c2bbba8SAndroid Build Coastguard Worker  Animal dog = Animal.create("dog", 4);
185*1c2bbba8SAndroid Build Coastguard Worker  assertEquals("dog", dog.name());
186*1c2bbba8SAndroid Build Coastguard Worker  assertEquals(4, dog.numberOfLegs());
187*1c2bbba8SAndroid Build Coastguard Worker
188*1c2bbba8SAndroid Build Coastguard Worker  // You probably don't need to write assertions like these; just illustrating.
189*1c2bbba8SAndroid Build Coastguard Worker  assertTrue(Animal.create("dog", 4).equals(dog));
190*1c2bbba8SAndroid Build Coastguard Worker  assertFalse(Animal.create("cat", 4).equals(dog));
191*1c2bbba8SAndroid Build Coastguard Worker  assertFalse(Animal.create("dog", 2).equals(dog));
192*1c2bbba8SAndroid Build Coastguard Worker
193*1c2bbba8SAndroid Build Coastguard Worker  assertEquals("Animal{name=dog, numberOfLegs=4}", dog.toString());
194*1c2bbba8SAndroid Build Coastguard Worker}
195*1c2bbba8SAndroid Build Coastguard Worker```
196*1c2bbba8SAndroid Build Coastguard Worker
197*1c2bbba8SAndroid Build Coastguard Worker### <a name="whats_going_on"></a>What's going on here?
198*1c2bbba8SAndroid Build Coastguard Worker
199*1c2bbba8SAndroid Build Coastguard WorkerAutoValue runs inside `javac` as a standard annotation processor. It reads your
200*1c2bbba8SAndroid Build Coastguard Workerabstract class and infers what the implementation class should look like. It
201*1c2bbba8SAndroid Build Coastguard Workergenerates source code, in your package, of a concrete implementation class which
202*1c2bbba8SAndroid Build Coastguard Workerextends your abstract class, having:
203*1c2bbba8SAndroid Build Coastguard Worker
204*1c2bbba8SAndroid Build Coastguard Worker*   package visibility (non-public)
205*1c2bbba8SAndroid Build Coastguard Worker*   one field for each of your abstract accessor methods
206*1c2bbba8SAndroid Build Coastguard Worker*   a constructor that sets these fields
207*1c2bbba8SAndroid Build Coastguard Worker*   a concrete implementation of each accessor method returning the associated
208*1c2bbba8SAndroid Build Coastguard Worker    field value
209*1c2bbba8SAndroid Build Coastguard Worker*   an `equals` implementation that compares these values in the usual way
210*1c2bbba8SAndroid Build Coastguard Worker*   an appropriate corresponding `hashCode`
211*1c2bbba8SAndroid Build Coastguard Worker*   a `toString` implementation returning a useful (but unspecified) string
212*1c2bbba8SAndroid Build Coastguard Worker    representation of the instance
213*1c2bbba8SAndroid Build Coastguard Worker
214*1c2bbba8SAndroid Build Coastguard WorkerYour hand-written code, as shown above, delegates its factory method call to the
215*1c2bbba8SAndroid Build Coastguard Workergenerated constructor and voilà!
216*1c2bbba8SAndroid Build Coastguard Worker
217*1c2bbba8SAndroid Build Coastguard WorkerFor the `Animal` example shown above, here is [typical code AutoValue might
218*1c2bbba8SAndroid Build Coastguard Workergenerate](generated-example.md).
219*1c2bbba8SAndroid Build Coastguard Worker
220*1c2bbba8SAndroid Build Coastguard WorkerNote that *consumers* of your value class *don't need to know any of this*. They
221*1c2bbba8SAndroid Build Coastguard Workerjust invoke your provided factory method and get a well-behaved instance back.
222*1c2bbba8SAndroid Build Coastguard Worker
223*1c2bbba8SAndroid Build Coastguard Worker## <a name="warnings"></a>Warnings
224*1c2bbba8SAndroid Build Coastguard Worker
225*1c2bbba8SAndroid Build Coastguard WorkerBe careful that you don't accidentally pass parameters to the generated
226*1c2bbba8SAndroid Build Coastguard Workerconstructor in the wrong order. You must ensure that **your tests are
227*1c2bbba8SAndroid Build Coastguard Workersufficient** to catch any field ordering problem. In most cases this should be
228*1c2bbba8SAndroid Build Coastguard Workerthe natural outcome from testing whatever actual purpose this value class was
229*1c2bbba8SAndroid Build Coastguard Workercreated for! In other cases a very simple test like the one shown above is
230*1c2bbba8SAndroid Build Coastguard Workerenough. Consider switching to use the [builder option](builders.md) to avoid
231*1c2bbba8SAndroid Build Coastguard Workerthis problem.
232*1c2bbba8SAndroid Build Coastguard Worker
233*1c2bbba8SAndroid Build Coastguard WorkerWe reserve the right to **change the `hashCode` implementation** at any time.
234*1c2bbba8SAndroid Build Coastguard WorkerNever persist the result of `hashCode` or use it for any other unintended
235*1c2bbba8SAndroid Build Coastguard Workerpurpose, and be careful never to depend on the order your values appear in
236*1c2bbba8SAndroid Build Coastguard Workerunordered collections like `HashSet`.
237*1c2bbba8SAndroid Build Coastguard Worker
238*1c2bbba8SAndroid Build Coastguard Worker## <a name="why"></a>Why should I use AutoValue?
239*1c2bbba8SAndroid Build Coastguard Worker
240*1c2bbba8SAndroid Build Coastguard WorkerSee [Why AutoValue?](why.md).
241*1c2bbba8SAndroid Build Coastguard Worker
242*1c2bbba8SAndroid Build Coastguard Worker## <a name="versions"></a>What Java versions does it work with?
243*1c2bbba8SAndroid Build Coastguard Worker
244*1c2bbba8SAndroid Build Coastguard WorkerAutoValue requires that your compiler be at least Java 8. However, the code that
245*1c2bbba8SAndroid Build Coastguard Workerit generates is compatible with Java 7. That means that you can use it with
246*1c2bbba8SAndroid Build Coastguard Worker`-source 7 -target 7` or (for Java 9+) `--release 7`.
247*1c2bbba8SAndroid Build Coastguard Worker
248*1c2bbba8SAndroid Build Coastguard Worker## <a name="more_howto"></a>How do I...
249*1c2bbba8SAndroid Build Coastguard Worker
250*1c2bbba8SAndroid Build Coastguard WorkerHow do I...
251*1c2bbba8SAndroid Build Coastguard Worker
252*1c2bbba8SAndroid Build Coastguard Worker*   ... [also generate a **builder** for my value class?](howto.md#builder)
253*1c2bbba8SAndroid Build Coastguard Worker*   ... [use AutoValue with a **nested** class?](howto.md#nested)
254*1c2bbba8SAndroid Build Coastguard Worker*   ... [use (or not use) JavaBeans-style name **prefixes**?](howto.md#beans)
255*1c2bbba8SAndroid Build Coastguard Worker*   ... [use **nullable** properties?](howto.md#nullable)
256*1c2bbba8SAndroid Build Coastguard Worker*   ... [perform other **validation**?](howto.md#validate)
257*1c2bbba8SAndroid Build Coastguard Worker*   ... [use a property of a **mutable** type?](howto.md#mutable_property)
258*1c2bbba8SAndroid Build Coastguard Worker*   ... [use a **custom** implementation of `equals`, etc.?](howto.md#custom)
259*1c2bbba8SAndroid Build Coastguard Worker*   ... [have AutoValue implement a concrete or default
260*1c2bbba8SAndroid Build Coastguard Worker    method?](howto.md#concrete)
261*1c2bbba8SAndroid Build Coastguard Worker*   ... [have multiple **`create`** methods, or name it/them
262*1c2bbba8SAndroid Build Coastguard Worker    differently?](howto.md#create)
263*1c2bbba8SAndroid Build Coastguard Worker*   ... [**ignore** certain properties in `equals`, etc.?](howto.md#ignore)
264*1c2bbba8SAndroid Build Coastguard Worker*   ... [have AutoValue also implement abstract methods from my
265*1c2bbba8SAndroid Build Coastguard Worker    **supertypes**?](howto.md#supertypes)
266*1c2bbba8SAndroid Build Coastguard Worker*   ... [use AutoValue with a **generic** class?](howto.md#generic)
267*1c2bbba8SAndroid Build Coastguard Worker*   ... [make my class Java- or GWT\-**serializable**?](howto.md#serialize)
268*1c2bbba8SAndroid Build Coastguard Worker*   ... [use AutoValue to **implement** an **annotation**
269*1c2bbba8SAndroid Build Coastguard Worker    type?](howto.md#annotation)
270*1c2bbba8SAndroid Build Coastguard Worker*   ... [also include **setter** (mutator) methods?](howto.md#setters)
271*1c2bbba8SAndroid Build Coastguard Worker*   ... [also generate **`compareTo`**?](howto.md#compareTo)
272*1c2bbba8SAndroid Build Coastguard Worker*   ... [use a **primitive array** for a property
273*1c2bbba8SAndroid Build Coastguard Worker    value?](howto.md#primitive_array)
274*1c2bbba8SAndroid Build Coastguard Worker*   ... [use an **object array** for a property value?](howto.md#object_array)
275*1c2bbba8SAndroid Build Coastguard Worker*   ... [have one `@AutoValue` class **extend** another?](howto.md#inherit)
276*1c2bbba8SAndroid Build Coastguard Worker*   ... [keep my accessor methods **private**?](howto.md#private_accessors)
277*1c2bbba8SAndroid Build Coastguard Worker*   ... [expose a **constructor**, not factory method, as my public creation
278*1c2bbba8SAndroid Build Coastguard Worker    API?](howto.md#public_constructor)
279*1c2bbba8SAndroid Build Coastguard Worker*   ... [use AutoValue on an **interface**, not abstract
280*1c2bbba8SAndroid Build Coastguard Worker    class?](howto.md#interface)
281*1c2bbba8SAndroid Build Coastguard Worker*   ... [**memoize** ("cache") derived properties?](howto.md#memoize)
282*1c2bbba8SAndroid Build Coastguard Worker*   ... [memoize the result of `hashCode` or
283*1c2bbba8SAndroid Build Coastguard Worker    `toString`?](howto.md#memoize_hash_tostring)
284*1c2bbba8SAndroid Build Coastguard Worker*   ... [make a class where only one of its properties is ever
285*1c2bbba8SAndroid Build Coastguard Worker    set?](howto.md#oneof)
286*1c2bbba8SAndroid Build Coastguard Worker*   ... [copy annotations from a class/method to the implemented
287*1c2bbba8SAndroid Build Coastguard Worker    class/method/field?](howto.md#copy_annotations)
288*1c2bbba8SAndroid Build Coastguard Worker*   ... [create a **pretty string** representation?](howto.md#toprettystring)
289*1c2bbba8SAndroid Build Coastguard Worker
290*1c2bbba8SAndroid Build Coastguard Worker<!-- TODO(kevinb): should the above be only a selected subset? -->
291