-
Notifications
You must be signed in to change notification settings - Fork 0
@Equiv
kobo edited this page Sep 13, 2010
·
5 revisions
If you wrote the following groovy code:
static class Sample {
@Equiv
String name
@Equiv
String value
String ignored
}
then you could use equals method and hashCode method:
def s1 = new Sample(name:'John', value:'Good', ignored:'Garbage')
def s2 = new Sample(name:'John', value:'Good', ignored:'Gold')
def s3 = new Sample(name:'John', value:'Bad', ignored:'Garbage')
def s4 = new Sample(name:'Mike', value:'Good', ignored:'Garbage')
assert s1 == s1
assert s1 == s2
assert s1 != s3
assert s1 != s4
assert s1.hashCode() == s1.hashCode()
assert s1.hashCode() == s2.hashCode()
assert s1.hashCode() != s3.hashCode()
assert s1.hashCode() != s4.hashCode()