Data classes

Brian Goetz brian.goetz at
Thu Nov 2 14:00:38 UTC 2017

> This looks great!
> One thing springs to mind with the accessors: Is it possible that the
> generated accessor methods could participate in the implementation of
> interfaces? For example:
>    interface Vector
>    {
>      double x();
>      double y();
>      double z();
>    }
>    __data class Vector3 (double x, double y, double z)
>      implements Vector { }
> The Vector3 type would automatically get x(), y(), and z() methods
> based on the field declarations. This may imply, of course, that the
> fields are public by default.

This is exactly how it would work.  The Vector3 class acquires x(), y(), 
and z() accessors, and since the interface Vector specifies these, and 
Vector3 <: Vector, then those accessors are the implementations of the 
Vector methods.

More information about the amber-spec-experts mailing list