Mark Florence
Mark Florence

Reputation: 363

Is there a static Groovy call operator?

I know I can create a call operator for a Groovy class like this:

class MyCallable {
    int call(int x) {           
        2*x
    }
}

def mc = new MyCallable()
assert mc(2) == 4 

But can I create a static call method?

class MyStaticCallable {
    static int call(int x) {           
        2*x
    }
}

assert MyStaticCallable(2) == 4 

Many thanks for any help!

Upvotes: 2

Views: 309

Answers (1)

tim_yates
tim_yates

Reputation: 171084

No, you'd have to do

MyStaticCallable.call(2)

Upvotes: 1

Related Questions