Java内省和反射 [英] Java introspection and reflection

查看:21
本文介绍了Java内省和反射的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

谁能解释一下Java反射和内省的使用?什么时候需要同时使用?

解决方案

Reflection(取自 oracle java 教程)

<块引用>

反射通常用于需要能够检查或修改在 Java 虚拟机中运行的应用程序的运行时行为的程序.这是一个相对高级的特性,只应由对语言基础有很强掌握的开发人员使用.考虑到这一点,反射是一种强大的技术,可以让应用程序执行原本不可能执行的操作.

自省(取自 sun java bean 教程存档)

<块引用>

自省是分析 bean 设计模式以揭示 bean 的属性、事件和方法的自动过程.此过程控制 bean 操作和属性的发布和发现.

Introspection 使用反射,Introspection 和 Reflection 的关系可以看成类似于 JavaBeans 和其他 Java 类.

可能值得一看 "反射&自省:暴露的对象",其中详细介绍了性能和用法.请注意,文章已过时,1998 年.

希望这会有所帮助.

Can any one explain the use of Java reflection and introspection? When we need to use both?

解决方案

Reflection (taken from oracle java tutorial)

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.

Introspection (taken from archive of sun java beans tutorial)

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.

Introspection uses reflection, the relationship between Introspection and Reflection can be seen as similar to JavaBeans and other Java classes.

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.

Hope this helps.

这篇关于Java内省和反射的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆