DISCUSSION: Bean/Data classes

Lawrence Kesteloot lk at teamten.com
Wed Mar 25 15:59:35 PDT 2009


On Wed, Mar 25, 2009 at 3:33 PM, Stephen Colebourne
<scolebourne at joda.org> wrote:
> Finally, I should say that of all the things Java lacks, I think
> properties is the biggest - bigger than closures.

I thought that Josh and Neal were in agreement on being against
properties. I don't remember the reasoning. Something about
encouraging mutable data structures? All the data classes I've made in
the last year have been immutable. Maybe we could try a syntax for
that?

public class Person final {
    String forename;
    String surname;
}

That would make the fields private, generate the getters,
constructors, toString/hash/equals (per Reinier), and perhaps "with"
methods that return a variant with some field modified. Not sure what
to do about fields of mutable types like Date. Maybe it would only
generate constructors/getters/"with" methods for fields that are also
immutable. The rest you have to write yourself or your clients can't
get at the data.

It may be too late to go down the functional path with Java.

Lawrence



More information about the coin-dev mailing list