Data classes
Maurizio Cimadamore
maurizio.cimadamore at oracle.com
Thu Nov 2 11:31:06 UTC 2017
Hi Mark,
the code that is generated on a datum is essentially like real code that
you would otherwise have typed yourself. In other word, think of it as
ACC_MANDATED, not as ACC_SYNTHETIC. It is something that the compiler
can fully reason about during type-checking and, as a consequence, it
means that, yes, you can implement an interface via datum _mandated_
methods.
Cheers
Maurizio
On 02/11/17 10:46, Mark Raynsford wrote:
> On 2017-11-01T14:53:40 -0400
> 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.
> 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.
>
> I don't see any obvious reasons why this couldn't work, but you've
> almost certainly thought further than I have on the subject.
>
More information about the amber-spec-experts
mailing list