PROPOSAL: Auto-assignment Parameters
james lowden
jl0235 at yahoo.com
Wed Mar 25 10:39:36 PDT 2009
Shouldn't it still be possible to infer, as in:
public data class Foo {
private final int must_be_positive;
public Foo (this.must_be_positive) throws SomeException {
if (must_be_positive < 0)
throw new SomeException ("It wasn't positive");
}
}
-JL
--- On Wed, 3/25/09, Mark Mahieu <markmahieu at googlemail.com> wrote:
> From: Mark Mahieu <markmahieu at googlemail.com>
> Subject: Re: PROPOSAL: Auto-assignment Parameters
> To: jl0235 at yahoo.com
> Cc: coin-dev at openjdk.java.net
> Date: Wednesday, March 25, 2009, 12:33 PM
> Hi James,
>
> I looked into inferring the parameter types, and while it
> does work quite well for 'brain-dead' POJO classes,
> it was not so great when you actually want to put some real
> code in the constructor, for example to throw an exception
> if a parameter value is not valid.
>
> The auto-assignment proposal is very much aimed at helping
> programmers with code they actually have to *write* (and
> therefore read and maintain), rather than just generate. If
> it happens to help with the latter as well, that's
> great.
>
> Mark
>
>
> On 25 Mar 2009, at 13:41, james lowden wrote:
>
> >
> > I'd like to see both.
> Auto-getters/setters/equals/etc. would be really, really
> nice, but it would also be valuable to have a way of
> specifying a variety of different constructors to generate,
> which Mark's proposal would allow for. Example:
> >
> > public data class Foo {
> > private final int x;
> > private final int y;
> > private final String foo;
> >
> > public Foo (this.x) {}
> >
> > public Foo (this.foo, this.y) {}
> > }
> >
> >
> > (I eliminated the types from the automagical
> constructors, as they can be inferred by the compiler.)
More information about the coin-dev
mailing list