首页 > 代码库 > Java reflection
Java reflection
Object Reflection is a feature in Java which provides a way to get reflective information about
Java classes and objects, such as:
1 Getting information about methods and fields present inside the class at run time
2 Creating a new instance of a class
3 Getting and setting the object fields directly by getting field reference, regardless of
what the access modifier is.
Why it is useful:
1 Helps in observing or manipulating the runtime behavior of applications
2 Useful while debugging and testing applications, as it allows direct access to methods,
constructors, fields, etc
try { Class c = Class.forName("java.util.ArrayList"); Method m[] = c.getDeclaredMethods(); for (int i = 0; i < m.length; i++) { System.out.println(m[i].toString()); } System.out.println(); Field[] f = c.getDeclaredFields(); for (int i = 0; i < f.length; i++) { System.out.println(f[i].toString()); } } catch (Throwable e) { System.err.println(e); }
Java reflection
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。