Data classes

Ryan Schmitt rschmitt at pobox.com
Thu Nov 2 01:01:20 UTC 2017


What I don't see in this proposal, and perhaps it's out of scope, is any
unifying abstraction for data types in Java. The writeup mentions that "our
main tool for data abstraction is classes," but that isn't actually true.
Data classes in Java are almost universally concretions, with no unifying
abstraction or type system relationship other than java.lang.Object.
Generic access, construction, and serialization can only be realized by
extralinguistic means, such as reflection. I can't even iterate over the
names and types of a given data class without reflection; that's not very
abstract. This lack of abstraction is costly; for example, we waste tons of
time and effort doing things like copying data between equivalent, but
non-interoperable, class representations (cf. tools like Dozer [1]).

The current proposal is a huge improvement over the status quo, but I think
it is still too firmly in the "boilerplate reduction" mindset. My viewpoint
is that what Java is most fundamentally missing is a true first-class
abstraction for data and values. I don't think this perspective is
currently reflected in the "meet the elephant" section; you'd probably need
to add "Clojure Chris" or something. In particular, the idea that we need
*first-class* abstractions (as opposed to the "let's reboot reflection"
line of thinking) for values clearly comes from languages like Clojure (see
especially [2]), but I don't see any reason why statically typed languages
cannot also abstract over data. It's also worth considering that if a
common data abstraction can be established, it may be possible to retrofit
many existing data class implementations into it (e.g. Lombok, Immutables,
AutoValue, ...), and the built-in Java solution (the __data classes
proposed here) can simply be one instance of it.

[1] http://dozer.sourceforge.net/
[2] https://www.youtube.com/watch?v=2V1FtfBDsLU


On Wed, Nov 1, 2017 at 11:53 AM, Brian Goetz <brian.goetz at oracle.com> wrote:

> At the following URL, please find a writeup containing our current
> thoughts on Data Classes for Java:
>
>     http://cr.openjdk.java.net/~briangoetz/amber/datum.html
>
> Comments welcome!
>
> We'll be making a prototype available soon for folks to play with.
>


More information about the amber-spec-observers mailing list