Over a million developers have joined DZone.

About Reflection…

DZone's Guide to

About Reflection…

· Java Zone ·
Free Resource

Verify, standardize, and correct the Big 4 + more– name, email, phone and global addresses – try our Data Quality APIs now at Melissa Developer Portal!

I never thought that will be faced with the need to write code that analyzes itself, but recently it happened. It should be noted that many developers do not use this method under any circumstances ... But it turned out that this code is incredibly flexible. Why?

Writing such a code has led me to release the following features:

  1. Self-analysis enables you to create multiple configurations at the level of code that makes the system flexible and modular.
  2. Having defined the interface (I do not mean Java interfaces) of the analyzed classes, you do not need to make any (!) changes in the code. Maybe you just you want to use annotations, which still remains a very flexible solution. ;)
  3. We get the independence of code from the existence and correctness of CDI. Of course, if you have correctly written the analyzing code...
  4. The code's logic cuts a lot of extra code that validates the use of dependency.
  5. And the most attractive, that it becomes possible to create a common interface to exchange parameters! You no longer need to think and worry about the number of parameters in the called method, you simply create a special object, the properties of which method will be determined.

The advantages are very attractive to me, but maybe they are insignificant for other developers because of the obvious problems:

  1. It is very difficult to determine the rules of the code analysis in the project. 
  2. It is difficult to unify these rules for the allocation of the universal functionality.
  3. Exchanging interface parameters is not always possible to unify even in any one module in the project without unnecessary complications in the architecture.

Solving these problems may leads to a very convenient framework, some of the makings of a functional already exist in specialized libraries (Spring Forms, Hibernate).

With all the charms that I found for myself in such an approach, you should be extremely careful with the performance ... Self-examination greatly slows down the system, so the use of reflection is necessary only when the gains from such an analysis (eg, cutting off unnecessary computations) will be significantly greater than the losses from the introspection.

Developers! Quickly and easily gain access to the tools and information you need! Explore, test and combine our data quality APIs at Melissa Developer Portal – home to tools that save time and boost revenue. Our APIs verify, standardize, and correct the Big 4 + more – name, email, phone and global addresses – to ensure accurate delivery, prevent blacklisting and identify risks in real-time.


Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}