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

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -