Add method to Closure

前端 未结 2 1745
Happy的楠姐
Happy的楠姐 2021-01-15 16:17

I\'ve added a method to Closure\'s metaClass, but I don\'t seem to be able to get a reference for the instance the method is being called on. In th

2条回答
  •  囚心锁ツ
    2021-01-15 16:43

    The problem is that Closure.metaclass and { -> }.metaClass are the different instances.

    println (Closure.metaClass)
    println ({ -> }.metaClass)
    

    yields:

    org.codehaus.groovy.runtime.HandleMetaClass@12f5f0d
    org.codehaus.groovy.runtime.metaclass.ClosureMetaClass@192d8d6
    

提交回复
热议问题