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 -

How to get the ip address of VM and use it to configure SSH connection dynamically in Ansible -

javascript - Get parameter of GET request -