Java内省和反射
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2044446/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Java introspection and reflection
提问by RKCY
Can any one explain the use of Java reflection and introspection? When we need to use both?
任何人都可以解释Java反射和内省的使用吗?当我们需要同时使用两者时?
采纳答案by Anthony Forloney
Reflection (taken from oracle java tutorial)
反射(取自oracle java教程)
Reflection is commonly used by programs which require the ability to examine or modify the runtime behavior of applications running in the Java virtual machine. This is a relatively advanced feature and should be used only by developers who have a strong grasp of the fundamentals of the language. With that caveat in mind, reflection is a powerful technique and can enable applications to perform operations which would otherwise be impossible.
反射通常由需要能够检查或修改在 Java 虚拟机中运行的应用程序的运行时行为的程序使用。这是一个相对高级的功能,应该只由对语言基础有很强掌握的开发人员使用。考虑到这一点,反射是一种强大的技术,可以使应用程序执行原本不可能执行的操作。
Introspection (taken from archive of sun java beans tutorial)
自省(取自sun java beans 教程存档)
Introspection is the automatic process of analyzing a bean's design patterns to reveal the bean's properties, events, and methods. This process controls the publishing and discovery of bean operations and properties.
自省是分析 bean 设计模式以揭示 bean 的属性、事件和方法的自动过程。此过程控制 bean 操作和属性的发布和发现。
Introspection uses reflection, the relationship between Introspection and Reflection can be seen as similar to JavaBeans and other Java classes.
Introspection 使用反射,Introspection 和 Reflection 的关系可以看成类似于 JavaBeans 和其他 Java 类。
It might be worth while to look at "Reflection & Introspection: Objects Exposed"where it goes into detail regarding perfomance and usage. Please note that the article is outdated, 1998.
可能值得一看“反射和内省:暴露的对象”,其中详细介绍了性能和用法。请注意,该文章已过时,1998 年。
Hope this helps.
希望这可以帮助。