def array = [1,2,3,4,5]
println 3 in array
版画
true
.我需要重载什么才能支持 in
对于任何对象?示例:
class Whatever {
def addItem(item) {
// add the item
}
}
def w = new Whatever()
w.addItem("one")
w.addItem("two")
println "two" in w
我知道我可以将这个类使用的集合设为公开,但我想使用
in
反而。
最佳答案
我在 Groovy 邮件列表上询问过。 Here's线程。答案是isCase
class A
{
def isCase(o) {
return false;
}
}
a = new A()
println 6 in a // returns false
关于groovy - 如何在 Groovy 中重载 in 运算符?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1582325/