Groovy: How to get Type on which a static method is called? -
when static method defined on base class called using child class, how find called on child class type?:
class base { static def method(){ println "class on method called? ${this}" } } class child extends base {} child.method()
in code above, this
rightly points base class.
i don't think can done actual static methods, nice alternative use groovy expandometaclass add static closure method. inside said closure, can access calling class delegate. i.e.
base.metaclass.static.anothermethod = { println "class on method called? ${delegate}" }
calling base.anothermethod() have delegate referring base , calling child.anothermethod have pointing child.
Comments
Post a Comment