@Documented @Retention(value=SOURCE) @Target(value={TYPE,METHOD,CONSTRUCTOR}) public @interface AutoFinal
Example usage:
@groovy.transform.AutoFinal
class Person {
final String first, last
Person(String first, String last) {
this.first = first
this.last = last
}
String fullName(boolean reversed = false, String separator = ' ') {
"${reversed ? last : first}$separator${reversed ? first : last}"
}
}
def js = new Person('John', 'Smith')
assert js.fullName() == 'John Smith'
assert js.fullName(true, ', ') == 'Smith, John'
for this case, the constructor for the Person
class will be
equivalent to the following code:
Person(final String first, final String last) { //... }And after normal default parameter processing takes place, the following overloaded methods will exist:
String fullName(final boolean reversed, final String separator) { ... } String fullName(final boolean reversed) { fullName(reversed, ' ') } String fullName() { fullName(false) }