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.
精彩评论