我有以下对象:
package com.rock
object Asteriod {
val orbitDiam = 334322.3
val radius = 3132.3
val length = 323332.3
val elliptical = false
}
如何使用 Java 反射来获取每个变量的值?我可以从对象中获取方法,但似乎无法弄清楚如何获取字段。这可能吗?
Class<?> clazz = Class.forName("com.rock.Asteriod$");
Field field = clazz.getField("MODULE$");
// not sure what to do to get each of the variables?????
谢谢!