Skip to: Site menu | Main content

Groovy 

      Download | Documentation | Developers | Community

An agile dynamic language for the Java Platform

ExpandoMetaClass - Static Methods Add comment to Wiki View in Wiki Edit Wiki page Printable Version

ExpandoMetaClass - Adding static methods

Static methods can also be added using the same technique as instance methods with the addition of the "static" qualifier before the method name:

class Book {
   String title
}

Book.metaClass.'static'.create << { String title -> new Book(title:title) }

def b = Book.create("The Stand")