Groovy Mixin on Instance (Dynamic Mixin)

Posted by david on Stack Overflow See other posts from Stack Overflow or by david
Published on 2010-03-21T14:35:33Z Indexed on 2010/03/21 14:41 UTC
Read the original article Hit count: 467

Filed under:
|
|

I'm trying to achieve following:

class A {
  def foo() { "foo" }
}

class B {
  def bar() { "bar" }
}

A.mixin B
def a = new A()

a.foo() + a.bar()

with one significant difference - I would like to do the mixin on the instance:

a.mixin B

but this results in

groovy.lang.MissingMethodException: No signature of method: A.mixin() is applicable for argument types: (java.lang.Class) values: [class B]

Is there a chance to get this working like proposed in the Groovy Mixins JSR?

© Stack Overflow or respective owner

Related posts about groovy

Related posts about mixin