1for (var prop in obj) {
2 if (Object.prototype.hasOwnProperty.call(obj, prop)) {
3 // do stuff
4 }
5}
1import java.lang.reflect.*;
2
3public class DumpFields {
4 public static void main(String[] args) {
5 inspect(String.class);
6 }
7 static <T> void inspect(Class<T> klazz) {
8 Field[] fields = klazz.getDeclaredFields();
9 System.out.printf("%d fields:%n", fields.length);
10 for (Field field : fields) {
11 System.out.printf("%s %s %s%n",
12 Modifier.toString(field.getModifiers()),
13 field.getType().getSimpleName(),
14 field.getName()
15 );
16 }
17 }
18}
1for (var prop in obj) {
2 if (Object.prototype.hasOwnProperty.call(obj, prop)) {
3 // do stuff
4 }
5}
6