1

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.

Nightwolf
  • 4,495
  • 2
  • 21
  • 29

1 Answers1

4

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

tim_yates
  • 167,322
  • 27
  • 342
  • 338