Wednesday, November 30, 2011

Lets reflect, shall we?





Ok, so last week I got my copy of Java Reflection in Action (http://amzn.to/uGp3Vo), from Amazon. I was eagerly waiting for it to arrive. Java reflection brings fear to most programmers. They are concerned with its complexity & of course the security risks and performance issues. Reading through the first chapter all three of those myths gets busted.


 It is incredible how much coding reflection can save. The main idea is to utilize reflection to perform tasks that we would do manually. For example, quoting directly from Chapter 1,


1. Examine the program for its structure or data.
2. Make decisions using the results of the examination.
3. Change the behavior, structure, or data of the program based upon the decisions.

You'd not expect the above tasks to be carried out by a program. it is a reasonable assumption. However, you can easily accomplish the above via reflection.

I would like to leave you with the following:

The java.lang.Object class is an instance of java.lang.Class class which itself extends java.lang.Object class and instance of java.lang.Class

Awesome!!,  isn't it? If you know reflection, you would not have trouble deciphering the above!
Add reflection to your toolkit today. This will be the first of many posts.


View Janith Perera's LinkedIn profileView Janith Perera's profile

No comments:

Post a Comment