Groovy extension method with traits? -


i'd know if there way add methods library classes using groovy traits.

from read here @mixin used this, or can use runtime mixin approach metaclass. since @mixin deprecated in favor of traits, chance achieve same behavior using traits or runtime mixin option?

thank you

groovy supports implementing traits dynamically @ runtime. allows "decorate" existing object using trait.

you can decorate object, however, afraid not possible decorate class instances have method available. see below simple example may or find more details here.

trait {     string extra() { "i'm method" }             }  class {                                            string dosomething() { 'something' }                 }  def s = new something()                          assert s.extra() == "i'm method"                                                assert s.dosomething() == 'something' 

Comments

Popular posts from this blog

Ansible - ERROR! the field 'hosts' is required but was not set -

customize file_field button ruby on rails -

SoapUI on windows 10 - high DPI/4K scaling issue -