Hi guys,

I've been looking into reflection and was wondering if anyone had any good tutorials or a good use for it. I understand how it works but can't think of an example of when it would actually be used.

A website with a task that needs reflection to solve the answer would be good ;)

Thanks in advance

Here are a few:

You can use it to hack into methods that are declared private. Eg there's a popular hack to give access to the Windows registry by gaining access to the private methods used by the Preferences class to read/write the registry for its own purposes. (NB I'm not advocating or endorsing such dubious practice).

Recent annotation-based advances use Reflection to combine annotations with the Java code they annotate.

Builder tools that work with JavaBeans use reflection to obtain the properties of the beans at runtime.

So in reality there is not really a need or use for Reflection in a normal programming. (not including dubious practices)

From reading articles since I posted this it seems it is mainly used as you said for things like netbeans and ecliplse. so its just something handy to know about but nothing I could really use in a program I make?

Personally I haven't seen any "ordinary" uses for it other than:
1. Data-driven logic - eg storing method names as data then executing them
2. Remote method invocation kinds of interfaces - where a method name is sent across a socket connection for the method to be executed at a server and the results returned.
It's certainly not a thing you use every day.

This question has already been answered. Start a new discussion instead.