views:

83

answers:

3

Hi there,

I'm looking for a solution to create an interface in runtime. I don't really know if this is possible in anyway.

Problem:

I've got a OSGi service which publishes a Map<String,String> where the key defines an action for this service. I want to publish this service directly as Hessianservice with spring but for this, I need to delcare an interface. Now I would like to create this interface at runtime.

+2  A: 

You can't really do that (unless you involve byte-code maniuplation/creation and I don't think that's the best path).

What good would a dynamically created interface do if you have nothing that could access that interface?

Or in other words: nothing can compile against a dynamically created interface (since it doesn't exist at compile-time, obviously). So who would be using it?

Joachim Sauer
A: 

Picked the following answer from another question. The example actually writes a new class, so may be this will help you.

JDK6 has a Java compiler API. However, it's not necessarily very easy to use.

A quick google pulled up this example usage.

Gaurav Saxena
+2  A: 

It's possible to create interfaces dynamically for example by generating it with a bytecode manipulation library such as ASM. But it won't be possible to use that interface, because no code can be compiled against it (unless you generate dynamically also the code which uses it).

What is it that you are trying to do?

Esko Luontola