Skip to content

Instantly share code, notes, and snippets.

@liviutudor
Created October 31, 2017 05:57
Show Gist options
  • Save liviutudor/bd6cde39807547d2a6999592c310e843 to your computer and use it in GitHub Desktop.
Save liviutudor/bd6cde39807547d2a6999592c310e843 to your computer and use it in GitHub Desktop.
Bean two with handcrafted comparison
package delegation
import groovy.transform.TupleConstructor
@TupleConstructor
class BeanTwo implements Comparable<BeanTwo> {
int yob
public int getAge() {
new Date().year - yob
}
@Override
int compareTo(BeanTwo o) {
if (!o) return false
if (this.is(o)) return false
return age <=> o.age
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment