API Reflection Interface

F

franck.dubois1970

Hello,

i would to specify interface constants with xml or property file
i think for that using api reflection but i don't see how to use
interface with api reflection ?

someone has idea ?

thanks in advance
Franck
 
J

Joshua Cranmer

Hello,

i would to specify interface constants with xml or property file
i think for that using api reflection but i don't see how to use
interface with api reflection ?

someone has idea ?

thanks in advance
Franck

If I understand you correctly, what you want to do is to be able to
specify the constants of an interface using another file. If so, then
the only way to do this is to generate class files dynamically; (most)
interface constants are compile-time constant expressions that, for all
practical purposes, cease to exist in the compiled code. Therefore,
these values need to be known at compile time, so the using classes need
to have a ready class file available at compile time.

In short: Can't be done with reflection at runtime.
 
G

Giovanni Azua

Hello Frank,

If you really absolutely need to do that there are ways and you may be
interested to look at the following two Reflection APIs:

- Class.forName
- Proxy.newProxyInstance

BUT I would seriously object the need to use this mechanism at
application level outside of a framework: there are cleaner alternatives for
an application e.g. how about a map of Factory instances keyed by some
ID that is read from your XML? so your application create instances that
that specified through configuration hmmm sounds like IoC to me.

Well anyway you can find an example of the Proxy.newProxyInstance here:
http://perfectjpattern.svn.sourcefo...ructural/composite/Composite.java?view=markup

The idea is: you give me an interface Class type that you may create
from a String loaded from an XML file see Class.forName, and I
give you a dynamic instance (implementation) of such interface.

I managed to componentize (or make a component out of) the Composite
Design Pattern that way. It is almost exactly the same mechanism as the
Mock objects use for testing.

HTH,
Giovanni
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top