Skip to content

Commit

Permalink
Document modern alternatives to AutoValue.
Browse files Browse the repository at this point in the history
If you are using Kotlin or Java ≥16 then AutoValue is no longer usually what you want.

RELNOTES=n/a
PiperOrigin-RevId: 430755878
  • Loading branch information
eamonnmcmanus authored and Google Java Core Libraries committed Feb 24, 2022
1 parent e01968d commit 36553ad
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 5 deletions.
11 changes: 9 additions & 2 deletions value/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,12 @@ less code and less room for error, while **not restricting your freedom** to
code almost any aspect of your class exactly the way you want it.

For more information, consult the
[detailed
documentation](userguide/index.md)
[detailed documentation](userguide/index.md).

**Note:** If you are using Kotlin then its
[data classes](https://kotlinlang.org/docs/data-classes.html) are usually more
appropriate than AutoValue. Likewise, if you are using a version of Java that
has [records](https://docs.oracle.com/en/java/javase/16/language/records.html),
then those are usually more appropriate. You can still use
[AutoBuilder](userguide/autobuilder.md) to make builders for data classes or
records.
10 changes: 9 additions & 1 deletion value/userguide/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,14 @@ AutoValue provides an easier way to create immutable value classes, with a lot
less code and less room for error, while **not restricting your freedom** to
code almost any aspect of your class exactly the way you want it.

**Note**: If you are using Kotlin then its
[data classes](https://kotlinlang.org/docs/data-classes.html) are usually more
appropriate than AutoValue. Likewise, if you are using a version of Java that
has [records](https://docs.oracle.com/en/java/javase/16/language/records.html),
then those are usually more appropriate. You can still use
[AutoBuilder](userguide/autobuilder.md)--> to make builders for data classes or
records.

This page will walk you through how to use AutoValue. Looking for a little more
persuasion? Please see [Why AutoValue?](why.md).

Expand Down Expand Up @@ -279,4 +287,4 @@ How do I...
* ... [create a **pretty string** representation?](howto.md#toprettystring)


<!-- TODO(kevinb): should the above be only a selected subset? -->
<!-- TODO(kevinb): should the above be only a selected subset?
6 changes: 4 additions & 2 deletions value/userguide/why.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
# Why use AutoValue?


AutoValue is the only solution to the value class problem in Java having all of
the following characteristics:
In versions of Java preceding
[records](https://docs.oracle.com/en/java/javase/16/language/records.html),
AutoValue is the only solution to the value class problem having all of the
following characteristics:

* **API-invisible** (callers cannot become dependent on your choice to use it)
* No runtime dependencies
Expand Down

0 comments on commit 36553ad

Please sign in to comment.