Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@mike-neck
Last active December 14, 2015 16:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mike-neck/5114818 to your computer and use it in GitHub Desktop.
Save mike-neck/5114818 to your computer and use it in GitHub Desktop.
/**
* 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