Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我想在 Groovy 中覆盖 >= 运算符,找到了这个页面,但我仍然不知道该怎么做。我有一个具有序列和金额属性的钞票类,我希望基于金额属性实现比较。
您不会覆盖>=运算符,而是实现compareTo:
>=
compareTo
class Foo implements Comparable { int val int compareTo(Object o) { return val <=> ((Foo) o).val } } f1 = new Foo(val: 5) f2 = new Foo(val: 10) println f1 <= f2 => true