Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java introspection and reflection

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

like image 701
RKCY Avatar asked Jan 11 '10 19:01

RKCY


People also ask

What is reflection and introspection in Java?

Introspection is concept of querying any reference (Object) RUNTIME for its type/class /method details .. Reflection is Java API which provides this ability . This is normally used when you want to deal Objects having No Type information available till Runtime (say for example Objects passed by External systems)

Does Java have introspection?

Lesson: Introspection (The Java™ Tutorials > JavaBeans(TM)) 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.

What is reflection and introspection?

Summary: 1. The term reflection denotes the act or state of being reflected while introspection has to do with the observation or examination of one's own mental and emotional state of mind.

What is Java reflection?

Reflection is a feature in the Java programming language. It allows an executing Java program to examine or "introspect" upon itself, and manipulate internal properties of the program. For example, it's possible for a Java class to obtain the names of all its members and display them.


1 Answers

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.

like image 92
Anthony Forloney Avatar answered Sep 21 '22 10:09

Anthony Forloney