What is Groovy's MetaClass used for?

前端 未结 2 1254
傲寒
傲寒 2020-12-10 01:50

What is the use of Meta-Class in Groovy and other OO programming languages?

2条回答
  •  臣服心动
    2020-12-10 02:03

    from Wikipedia

    In object-oriented programming, a metaclass is a class whose instances are classes. Just as an ordinary class defines the behavior of certain objects, a metaclass defines the behavior of certain classes and their instances. Not all object-oriented programming languages support metaclasses. Among those that do, the extent to which metaclasses can override any given aspect of class behavior varies. Each language has its own metaobject protocol, a set of rules that govern how objects, classes, and metaclasses interact.

    and

    Support in languages and tools

    The following are some of the most prominent programming languages that support metaclasses. Common Lisp, via CLOS Groovy Objective-C Python Perl, via the metaclass pragma, as well as Moose Ruby Smalltalk Some less widespread languages that support metaclasses include OpenJava, OpenC++, OpenAda, CorbaScript, ObjVLisp, Object-Z, MODEL-K, XOTcl, and MELDC.

提交回复
热议问题