Programming Language

What Is Reflection In Java?

Concept of Reflection in Computer Programs

With respect to the computer programs, reflection of a program is the capability of examining and modifying its assembly of data and operation at runtime. The data may include a set of values, meta-data or corollary at the same time. Reflection is used to alter the observable complexity for proper execution of the program. In a program consisting of reflection function, the codes are monitored and modified corresponding to the objective related to the codes given.  Java is a good example of reflection-oriented computer program.

Importance of Reflection in Java

Java is a reflection-oriented program. During compile time if the collection of abstract methods, classes and fields are unknown, then reflection assessing them at runtime, which allows the manifestation of new techniques and objects. The reflecting ability of Java makes its executions more positive. It allows you to type up such programs that are not instructed upon each and everything at compile time. Without specifying the interfaces a code would be written, for the reflection to configure the actual classes.

Reflection is a dynamic technique that proves to be high-powered if used in the correct manner. Java reflection has two main factors:

  1. Metadata

All the extra data i.e. techniques, fields, classes and constructors come under the heading of Metadata.

  1. Functionality

It allows you to manipulate the metadata, constructor and methods particularly.

 

 

What are the drawbacks of reflection in Java?

  • The eminent drawback of Java reflection is the slow performance because of the resolution at runtime instead of compile time. It is advised not to make use of reflection in such code executions where there is need of efficient conduct of applications.

 

  • The other drawback of reflection in Java is the accessing of data by the code which is not permitted in non-reflexive code. Reflection permits you to access fields/techniques of a class that are particular. These particularities are inaccessible to the non-reflexive code. In this case the code is ruined.

Reflection is considered as a high-level description of data manipulation and modification at runtime. Despite its major drawbacks, it is used for its convenient application for the automatic examination and amendment in the codes.

Leave a Reply