开发者

Groovy hasProperty/respondsTo

All the examples I see of using hasProperty or respondsTo show it being invoked on a metaClass. Is there a reason why these methods shouldn't be invoked on the object itself, like this:

def propertyName = 'time'

if (new Date().hasProperty(开发者_如何学编程propertyName))
  println 'yes'
else 
  println 'no'


The issue is discussed in this thread. Looks like they refer to the same thing in current versions of Groovy, but this was not always the case, as only the metaClass had that call.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜