The runtime dynamically obtains the value of the property (obtained by means of the method):
Method[] methods = Cls.getdeclaredmethods (); for (Method method:methods) { if (Method.getname (). StartsWith ("get")) { try { System.out.println ( Method.invoke (object)); } catch (Exception e) { } } }
The runtime dynamically obtains the value of the property (obtained through the property):
for (Field field:fields) { field.setaccessible (true); Try { Object val = (object) field.get (object); System.out.println (val); } catch (Exception e) { } }
Java Reflection provides detailed information about the properties, methods, and so on that can be compiled at runtime, enabling the Java language to implement dynamic language features
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Java reflection Gets the value of a run-time property