xref: /aosp_15_r20/external/auto/value/README.md (revision 1c2bbba85eccddce6de79cbbf1645fda32e723f0)
1*1c2bbba8SAndroid Build Coastguard Worker# AutoValue
2*1c2bbba8SAndroid Build Coastguard Worker
3*1c2bbba8SAndroid Build Coastguard Worker*Generated immutable value classes for Java 7+* <br />
4*1c2bbba8SAndroid Build Coastguard Worker***Kevin Bourrillion, Éamonn McManus*** <br />
5*1c2bbba8SAndroid Build Coastguard Worker**Google, Inc.**
6*1c2bbba8SAndroid Build Coastguard Worker
7*1c2bbba8SAndroid Build Coastguard Worker**Value classes** are extremely common in Java projects. These are classes for
8*1c2bbba8SAndroid Build Coastguard Workerwhich you want to treat any two instances with suitably equal field values as
9*1c2bbba8SAndroid Build Coastguard Workerinterchangeable. That's right: we're talking about those classes where you wind
10*1c2bbba8SAndroid Build Coastguard Workerup implementing `equals`, `hashCode` and `toString` in a bloated, repetitive,
11*1c2bbba8SAndroid Build Coastguard Workerformulaic yet error-prone fashion.
12*1c2bbba8SAndroid Build Coastguard Worker
13*1c2bbba8SAndroid Build Coastguard WorkerWriting these methods the first time is not too bad, with the aid of a few
14*1c2bbba8SAndroid Build Coastguard Workerhelper methods and IDE templates. But once written they continue to burden
15*1c2bbba8SAndroid Build Coastguard Workerreviewers, editors and future readers. Their wide expanses of boilerplate
16*1c2bbba8SAndroid Build Coastguard Workersharply decrease the signal-to-noise ratio of your code... and they love to
17*1c2bbba8SAndroid Build Coastguard Workerharbor hard-to-spot bugs.
18*1c2bbba8SAndroid Build Coastguard Worker
19*1c2bbba8SAndroid Build Coastguard WorkerAutoValue provides an easier way to create immutable value classes, with a lot
20*1c2bbba8SAndroid Build Coastguard Workerless code and less room for error, while **not restricting your freedom** to
21*1c2bbba8SAndroid Build Coastguard Workercode almost any aspect of your class exactly the way you want it.
22*1c2bbba8SAndroid Build Coastguard Worker
23*1c2bbba8SAndroid Build Coastguard WorkerFor more information, consult the
24*1c2bbba8SAndroid Build Coastguard Worker[detailed documentation](userguide/index.md).
25*1c2bbba8SAndroid Build Coastguard Worker
26*1c2bbba8SAndroid Build Coastguard Worker**Note:** If you are using Kotlin then its
27*1c2bbba8SAndroid Build Coastguard Worker[data classes](https://kotlinlang.org/docs/data-classes.html) are usually more
28*1c2bbba8SAndroid Build Coastguard Workerappropriate than AutoValue. Likewise, if you are using a version of Java that
29*1c2bbba8SAndroid Build Coastguard Workerhas [records](https://docs.oracle.com/en/java/javase/16/language/records.html),
30*1c2bbba8SAndroid Build Coastguard Workerthen those are usually more appropriate. You can still use
31*1c2bbba8SAndroid Build Coastguard Worker[AutoBuilder](userguide/autobuilder.md)
32*1c2bbba8SAndroid Build Coastguard Workerto make builders for data classes or records.
33