How do I overload the in operator in Groovy?

groovy, language-features, operator-overloading

Solution

I asked on the Groovy mailing list. Here's the thread. The answer is `isCase`

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

a = new A()
println 6 in a // returns false

Problem

``` def array = [1,2,3,4,5] println 3 in array ``` prints `true`. What do I need to overload to support `in` for any object? Example: ``` class Whatever { def addItem(item) { // add the item } } def w = new Whatever() w.addItem("one") w.addItem("two") println "two" in w ``` I know I could make the collection this class uses public, but I'd like to use `in` instead.

Original source