Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
这是我想要做的一个人为的例子,但最低限度地表达了所需的行为。我想引用正在调用属性访问的对象的实例。我首先尝试了“this”,但它指的是封闭类,而不是 MetaClass 或 String 实例。
String.metaClass.propertyMissing = { String name -> 'I do not exist, but my name is ' + <the String instance> + '.' + $name }
您可以使用“委托”来引用对象:
String.metaClass.propertyMissing = { String name -> "I do not exist, but my name is $delegate.$name" } println "a".me