大佬教程收集整理的这篇文章主要介绍了当Groovy的“metaClass”返回null时,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
import net.sf.json.groovy.JsonSlurper @Grab(group='net.sf.json-lib',module='json-lib',version='2.3',classifier='jdk15') def printMeta(obj) { obj.MetaClass.properties.each {println "Property: ${it.namE}"} } def raw = /{"test":"this is a test"}/ def json = new JsonSlurper().parseText(raw); printMeta (json);
我知道JsonSlurper使用元编程,为什么我会得到以下内容:
抓到:java.lang.NullPointerException:无法在Null对象上获取属性’properties’
在MetaTest.printMeta(MetaTest.groovy:17)
在MetaTest.run(MetaTest.groovy:24)
我完全没有想法.
谢谢!
以上是大佬教程为你收集整理的当Groovy的“metaClass”返回null时全部内容,希望文章能够帮你解决当Groovy的“metaClass”返回null时所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。