Reflection is one of those features that is severely underused when it comes to flexible coding. The Java language has an excellent means of handling the creation of objects based purely on class names. To start with, let’s just grab everything java needs to do reflection.
import java.lang.reflect.*
Now say we have an interface called ISomething and we want to allow people to write and compile their own implementations without actually having our packages in source form. This is useful when you want to ship a jar for example.
public interface ISomething
{
void doSomething();
}
We still aren’t actually using reflection yet. In terms of the interface you don’t have to do anything extra. Once it’s implemented and instantiated it’s exactly the same as if the implementation was hard coded in.
Now lets move on to creating our reflection based implementation.
Continue thusly