Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
/**
* GroovyASTTransformation の お話
*
* Annotation Based AST Transformations
*
* AST にアクセスする一つの手段が Annotation を介してアクセスする方法。
**/
/**
* 例 3 : @Canonical
**/
import groovy.transform.*
@Canonical
@EqualsAndHashCode (excludes = ['year', 'model'])
class Car {
String VIN
String engineNumber
int year
String model
}
def celsior = new Car (
VIN : 'UCF11989X02254931',
engineNumber : '1UZFE-083566',
year : 1998,
model : 'Celsior')
def crown = new Car (
VIN : 'S140C989X00344259',
engineNumber : '1UZFE-092317',
year : 1998,
model : 'Crown Magesta')
assert celsior != crown
def century = new Car (
VIN : 'UCF11989X02254931',
engineNumber : '1UZFE-083566',
year : 2004,
model : 'Century')
assert celsior != century
Assertion failed:
assert celsior != century
| | |
| | Car(UCF11989X02254931, 1UZFE-083566, 2004, Century)
| false
Car(UCF11989X02254931, 1UZFE-083566, 1998, Celsior)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment