grails - Want to check if object is in groovy list using .contains() or 'in' -


import groovy.transform.equalsandhashcode; @equalsandhashcode(includes="name") class activity {   public string name   public buildings = []   public rooms = [] set    activity(name) {     this.name = name   } }  thisactivity=new activity("activity") activityregistry = []  // false correct activityregistry.contains(thisactivity)  // add new item activity2 activityregistry << new activity("activity2")  // true????? activityregistry.contains(thisactivity) 

this code pretty straight forward, create activityregistry list, compare empty list object created. naturally test fails. create new object on fly using new insert list. compare list first object created, not part of list, , contains, or in passes. shed light on how? or why?

the ast "equalsandhashcode" use 'properties' class. properties, in groovy, declared without modifier ('public'), , getter/setter automatically generated.

in example, change public string name string name.

see : what 'properties' in groovy?


Comments