What are some appropriate and inappropriate uses of reflection in Java? -
java's reflection api powerful tool, not particularly object-oriented. situations appropriate (and conversely, inappropriate) use reflection?
in opinion...
appropriate (clean):
- instantiating root of dynamically-loaded implementation, such applet.
- use of
proxy
create proxy or mock implementation (may better @ compile time). - implementing interpreters allow unrestricted access java libraries. (note, security perspective interpreted code has effective privileges interpreter - can kind of dangerous.)
appropriate hacks:
- circumventing java language access controls in third party code absolutely have to.
- implementing "cross-cutting concern" such persistence.
- removing static dependencies load classes causing slower start up.
inappropriate:
- general circumventing java language access controls (includes testing).
- anything relies upon java language access rights given particular reflection-calling class.
- anywhere implementing interface work.
generally reflection easier generating source easier creating bytecode.
Comments
Post a Comment