How to create an interface in runtime

Assuming I have a class like

public class FooImpl
{
    public void bar(){};
}

Is there any way to create my runtime interface?

eg.

public interface Foo
{
    public void bar();
}

I studied the Javasssist , and the truth is a reflection of what I'm interested in using the interface for (as Esko Luontola and Ishai stated)

So, I need an interface that specifies a subset of the methods of the source class to create the proxy.

I realized that you need to worry about something like

  • Should you reuse this interface or create a new one each time?
  • A proxy class is a really new instance of type java.lang.reflect.Proxy, which can cause consequences depending on the use case.

, , ? - ?

, , (, , ) .

+5
2

/ - , , ASM, Javassist , , AspectJ.

: ? , . , , , . , , , , , ( , ).

+2

- Javassist, . Class.getMethods() - , Proxy, .

+1

All Articles