Groovy compiling despite error in function arguments

105 Views Asked by At

Is this legal in Groovy?

class RequestContext {
    def static requestContext

    def static setRequestContext(rc) {
        requestContext = rc
    }
}

Given the above I expect the following to fail at compile time using the groovy-eclipse-compiler:

RequestContext.setRequestContext()

Yet this passes and I'm trying to get this to fail at mvn compile time.

1

There are 1 best solutions below

0
On BEST ANSWER

It can't fail at compile time, because you might add that method dynamically at runtime via the metaclass, ie:

class Test {
}

Test.metaClass.static.woo = { -> println "yay" }

Test.woo() // prints 'yay'

To fail at compile time, you'd need to annotate the calling class with @CompileStatic or @TypeChecked