Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Recursive list fields
//'main' method must be in a class 'Rextester'. //Compiler version 1.8.0_111 import java.util.*; import java.lang.*; import java.lang.reflect.*; class MyInnerClass { private List<String> list; } class MyMidClass { private List<MyInnerClass> list; } class MyOuterClass { private List<MyMidClass> list; } class Rextester { public static void main(String args[]) { recursivelyPrintListField(MyOuterClass.class); } private static void recursivelyPrintListField(Class<?> clazz) { Field field = null; try { field = clazz.getDeclaredField("list"); } catch (NoSuchFieldException e) { System.out.println("No more list field"); return; } Type genericFieldType = field.getGenericType(); if(genericFieldType instanceof ParameterizedType){ ParameterizedType aType = (ParameterizedType) genericFieldType; Type[] fieldArgTypes = aType.getActualTypeArguments(); for(Type fieldArgType : fieldArgTypes){ Class<?> fieldArgClass = (Class<?>) fieldArgType; System.out.println("field type = " + fieldArgClass); recursivelyPrintListField(fieldArgClass); } } } }
run
|
edit
|
history
|
help
0
메소드구현하기-해결
output2
Add Two Numbers saved in linked lists
Catalan number optimised
Hello, World!
right swastik
Java Object structure dumper (iterative)
sfr
Hello world
rd dap da