如何在Groovy中重载in运算符?

Geo*_*Geo 7 groovy language-features operator-overloading

def array = [1,2,3,4,5]
println 3 in array
Run Code Online (Sandbox Code Playgroud)

打印true.我需要重载以支持in任何对象?

例:

class Whatever {
   def addItem(item) {
      // add the item
   }
}

def w = new Whatever()
w.addItem("one")
w.addItem("two")
println "two" in w
Run Code Online (Sandbox Code Playgroud)

我知道我可以使这个类使用public的集合,但我想in改用.

Geo*_*Geo 8

我在Groovy邮件列表上询问过.这是线程.答案是isCase

class A
{
  def isCase(o) {
    return false;
  }
}

a = new A()
println 6 in a // returns false
Run Code Online (Sandbox Code Playgroud)