Created
October 31, 2017 05:57
-
-
Save liviutudor/bd6cde39807547d2a6999592c310e843 to your computer and use it in GitHub Desktop.
Bean two with handcrafted comparison
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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