Reflection/List properties: Difference between revisions

Content added Content deleted
Line 179: Line 179:
Y int true
Y int true
</pre>
</pre>

=={{header|Groovy}}==
{{trans|Java}}
<lang groovy>import java.lang.reflect.Field

@SuppressWarnings("unused")
class ListProperties {
public int examplePublicField = 42
private boolean examplePrivateField = true

static void main(String[] args) {
ListProperties obj = new ListProperties()
Class clazz = obj.class

println "All public fields (including inherited):"
(clazz.fields).each { Field f ->
printf "%s\t%s\n", f, f.get(obj)
}
println()

println "All declared fields (excluding inherited):"
clazz.getDeclaredFields().each { Field f ->
f.accessible = true
printf "%s\t%s\n", f, f.get(obj)
}
}
}</lang>
{{out}}
<pre>All public fields (including inherited):
public int ListProperties.examplePublicField 42
public static transient boolean ListProperties.__$stMC false

All declared fields (excluding inherited):
public int ListProperties.examplePublicField 42
private boolean ListProperties.examplePrivateField true
private static org.codehaus.groovy.reflection.ClassInfo ListProperties.$staticClassInfo org.codehaus.groovy.reflection.ClassInfo@400cff1a
public static transient boolean ListProperties.__$stMC false
private transient groovy.lang.MetaClass ListProperties.metaClass groovy.lang.MetaClassImpl@275710fc[class ListProperties]
private static org.codehaus.groovy.reflection.ClassInfo ListProperties.$staticClassInfo$ null
private static java.lang.ref.SoftReference ListProperties.$callSiteArray java.lang.ref.SoftReference@525f1e4e</pre>


=={{header|J}}==
=={{header|J}}==