gujralam (1) [Avatar] Offline

I have started reading "Reflection in Action" and have following doubt related to example discussed in Chapter 1.

Details:- Author discusses that George has series of Java Visual components from various sources like, in-house, open-source, licensed, which do not share any common parent.

E.g. InHouseVisual in = new InHouseVisual();
OpenSourceVisual os = new OpenSourceVisual();
ThirdPartyVisual tp = new ThirdPartyVisual();

These components donot extend / implement a common parent and thus have common base class as "java.lang.Object"
However, these all have a setColor() method that we need to invoke as part of the requirements.

Question 1- Author suggests that reflection will help to call setColor() method irrespective of the object's concrete type.

I want to understand here, that since these objects have no common parent thus we need to explicitly create each of these individual objects.

Then as per my understanding, setColor() can be directly invoked on the specific object that we have instantiated.

I do not see merit in involving reflection since in current scenario these classes have NO common parent thus the easiest alternative is to directly invoke setColor() on object.

Request you to Please clarify this example to me.

Thank You!!