Data classes

Brian Goetz brian.goetz at oracle.com
Thu Nov 2 14:50:17 UTC 2017


That's a separate feature, which we're also thinking about.  Data 
classes give us one half of algebraic data types; sealed classes give us 
the other half.  But, since data classes stand just fine on their own 
without sealed classes, and are the more immediately useful of the two, 
we're working on this first.

On 11/2/2017 10:44 AM, Zheka Kozlov wrote:
> Also, it would be interesting to know how to model closed data class 
> hierarchies (like sealed in Scala). I suppose it should be something 
> like that:
>
> __data class ASTNode {
>     ASTNode() {} // make constructor package-private so no one outside 
> can inherit
> }
>
> __data class ASTNumber(double num) extends AST { }
> __data class ASTBinaryOperator(char op) extends AST { }
> ...
>
>
> 2017-11-02 21:29 GMT+07:00 Zheka Kozlov <orionllmain at gmail.com 
> <mailto:orionllmain at gmail.com>>:
>
>     Hi Brian.
>
>     I'm happy to see this proposal. This is very similar to how I
>     imagined data classes in Java. Just one thing that looks a bit
>     ugly to me is the empty curly braces after the data class
>     declaration. Can we omit them? Most of data classes will have no
>     members, so the redundant curly braces will clutter the code.
>
>
>     2017-11-02 1:53 GMT+07:00 Brian Goetz <brian.goetz at oracle.com
>     <mailto:brian.goetz at oracle.com>>:
>
>         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
>         <http://cr.openjdk.java.net/%7Ebriangoetz/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