Re: [again] AspectJ: solution to Java's repetitiveness? bean attributes
thufir wrote:
It seems arcane, but there is a way to do away with the boilerplate of
getters and setters:
public class NewBean {
public final Property<Integer> x = PropertyImpl.create();
}
I don't recall what we decided the last time we had this conversation.
I'm not sure it was even possible to use AspectJ like for this in the
general case. (Ie., it works in all circumstances.)
And as Lew pointed out, you forgo the Java doc comments when you forgo
the methods too. Doesn't sound like best practice.
Incidentally, in my editor I can type this:
public class NewBean {
private String name;
private int id;
//.. ctrl-space
}
....and press Ctrl-Space in place of the comment, and it will
automatically generate the getters, setters and a constructor too if I
want. Of course, I still have to add the Java doc comments, but it saves
my finger-tips some wear and tear.
Hmm, speaking of modifying the results of auto-generation, how would
AspectJ handle invariants? How would I check that "name" is set to
something non-null and contains at least a first name and a last name,
or that ID is with-in an acceptable range? You could do a reasonable
job with some types of constraints, of course, but it seems to me that
you'd often have to create your own setters, at least, to check various
invariants.
It does seem to me that 90% of the boilerplate could be handled by a
decent editor, and would be a lot simpler to maintain in the long run.
Just one opinion.