如何获取Groovy类的所有属性名称?
标题问了一下:如何获取Groovy类的所有属性名称?
它甚至可能吗? 我以为我可以使用类的集合语法,因为它似乎不起作用。
我正在使用groovy编译器2.4我得到一个java.util.LinkedHashMap
其中包含通过在groovy对象上调用getProperties()
返回的所有属性及其值。
class PropertyDemoClass { int firstProperty = 1; String secondProperty = "rhubarb" String thirdProperty = "custard" } PropertyDemoClass demoClass = new PropertyDemoClass() println demoClass.getProperties().toString()
这导致:
[firstProperty:1, secondProperty:rhubarb, class:class PropertyDemoClass, thirdProperty:custard]
看看MetaClass API 。
你可以使用Java Reflection API吗?
看一下java.lang.Class的getDeclaredFields 。
关于使用Reflection API的某种教程/指南 。
- Thread-6,RECV TLSv1 ALERT:致命,handshake_failure
- Groovy / Java在括号上拆分字符串“(”
- 在Java中使用GroovyClassLoader时,找不到类:org.apache.ivy.core.report.ResolveReport
- Jenkins如何查找给定的奴隶是否正在运行作业
- 如何在没有指定年份的情况下简单地解析日期?
- 打开https URL时出错:未设置keyCertSign位
- 如何使用params调用URL并在servlet中获取响应?
- 如何通过任务在gradle中设置环境变量?
- 如何使用logback禁用accessExternalDTD和entityExpansionLimit警告