Java introspection and reflection

后端 未结 1 737
暖寄归人
暖寄归人 2020-12-02 09:30

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

相关标签:
1条回答
  • 2020-12-02 09:42

    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.

    0 讨论(0)
提交回复
热议问题