PROPOSAL: Named method parameters

howard.lovatt at gmail.com howard.lovatt at gmail.com
Tue Apr 21 17:52:59 PDT 2009


I use the builder pattern successfully via my enhanced compiler ( pet  
project :) ):

https://pec.dev.java.net/nonav/compile/index.html

and in particular:

https://pec.dev.java.net/nonav/compile/javadoc/pec/compile/immutable/ImmutableValueConversions.html

The enhanced compiler enforces the pattern, ie if you get it wrong the  
compiler gives you an error message.

You can also use a simple structure like class, eg:

class Point {

static class Args {
int x = 0;
int y = 0;
}

final int x;

final iny y;

Point( Args args ) {
x = args.x;
y = args.y;
}

...

}

Which is used like:

Point p = new Point( new Point.Args() {{ x = 1; }} );

As the original post said you would only use this if there were a lot of  
arguments, therefore the overhead of typing "new Point.Args() {{ }}" is  
negligible.

-- Howard.



More information about the coin-dev mailing list