groovy define metaclass with its own custom methods and set it for the object -


is possible set metaclass object in groovy custom methods? mean kind of dynamic inheritance...

for example this

class original {     def my_method() { } }  class meta {     def meta_method() { } }  def obj = new original() obj.metaclass = new meta()  obj.meta_method() 

you can use traits achieve kind of things. it's little more "high level" directly manipuling metaclass

​class original {   def my_method() { }  }    trait meta {   def meta_method() { }  }    def obj = new original()​.withtraits meta ​obj.meta_method()​ 

see: http://docs.groovy-lang.org/next/html/documentation/core-traits.html#_implementing_a_trait_at_runtime


Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

javascript - Get parameter of GET request -

javascript - Twitter Bootstrap - how to add some more margin between tooltip popup and element -