Reputation: 58
From what I've read, the Groovy in
operator calls isCase
. However, I've had a little problem recently and it goes like this:
class Test {}
new Test() in Test
This returns true
. But when I switch it up to be:
class Test {}
new Test().isCase(Test)
It returns false
. I don't understand the reasoning and cause behind this exactly, and I'm sort of afraid the in
operator is hardcoded.
Upvotes: 1
Views: 516
Reputation: 2188
in
is a membership operator and is equivalent to calling isCase()
method. So according to groovy doc:
The membership operator (
in
) is equivalent to calling theisCase
method. In the context of aList
, it is equivalent to callingcontains
, like in the following example:
def list = ['Grace','Rob','Emmy'] assert ('Emmy' in list)
equivalent to calling
list.contains('Emmy')
orlist.isCase('Emmy')
So in your case it would be:
Test t = new Test()
println t in Test
println Test.isCase(t)
And it would print true in both cases. You are getting false as you are calling the method on wrong object: t.isCase(Test)
Upvotes: 2