Dónal
Dónal

Reputation: 187399

Groovy constructor problem

When the constructor of the class below is executed during my unit tests I get the error:

No signature of method: static grails.plugin.flashhelper.args.AnonymousArgumentsResolver.getDefaultMessages() is applicable for argument types: ([Ljava.lang.Object;) values: [[message number 1]]

class AnonymousArgumentsResolver extends AbstractArgumentsResolver {

    private final args

    AnonymousArgumentsResolver(methodArgs) {

        super(methodArgs[0], getDefaultMessages(methodArgs))

        this.args = methodArgs
    }

    private final getDefaultMessages(methodArgs) {

        if (methodArgs.size() > 1) {
            methodArgs[1..-1].find { it instanceof String || it instanceof List }
        }
    }
}

If I change getDefaultMessages to be a static method everything works fine. I've no idea why Groovy requires this method to be static?

Upvotes: 0

Views: 885

Answers (1)

tim_yates
tim_yates

Reputation: 171194

Wouldn't that also need to be static in java?

You are trying to call an instance method in a call to super(), where no instance yet exists...

Upvotes: 4

Related Questions