Allow single-line accessor (getter/setter) syntax with Checkstyle
Posted
by Sam3
on Stack Overflow
See other posts from Stack Overflow
or by Sam3
Published on 2010-04-30T09:41:28Z
Indexed on
2010/04/30
9:47 UTC
Read the original article
Hit count: 336
We'd like to have trivial Java property accessors using a single line syntax, so they take up much much less space, and are more readable (in terms of 'seeing' the set of accessors quickly). But we do want to enforce multi-line method syntax for everything else in our checkstyle configuration. But I'm not sure how to make this exception for accessors in Checkstyle config and suspect it may not be possible.
So we'd like our accessors to look something like this:
public String getFoo() { return foo; } public void setFoo(String foo) { this.foo = foo; }
[In fact we'd rather not have trivial accessors at all and instead just annotate the private member variables with @Property or something and have the accessors generated for us, since writing endless get and set code delivers no real benefit, but that's a general Java frustration and an aside as far as this question goes.]
© Stack Overflow or respective owner