Versions Compared


  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migrated to Confluence 5.3


Borrowing methods from other classes

ExpandoMetaClass - Borrowing Methods from other classes

With ExpandoMetaClass you can also use Groovy's method pointer syntax to borrow methods from other classes. For example:

Code Block
class Person {
    String name
class MortgageLender {
   def borrowMoney() {
      "buy house"

def lender = new MortgageLender()

Person.metaClass.buyHouse = lender.&borrowMoney

def p = new Person()

assert "buy house" == p.buyHouse()