我试图用 Xtend 重载现有外部类的运算符,但它不起作用。我不能在类源中写,比如 BigIntegerExtension。我该怎么做?
回答
答案很简单。我们可以使用运算符重载覆盖我们想要的任何运算符。
// IntVar = IntVar
def static operator_equals(IntVar a, IntVar b) {
return IntConstraintFactory.arithm(a, "=", b)
}
我试图用 Xtend 重载现有外部类的运算符,但它不起作用。我不能在类源中写,比如 BigIntegerExtension。我该怎么做?
回答
答案很简单。我们可以使用运算符重载覆盖我们想要的任何运算符。
// IntVar = IntVar
def static operator_equals(IntVar a, IntVar b) {
return IntConstraintFactory.arithm(a, "=", b)
}