How do I extend Java classes by Reflection?

后端 未结 4 1885

I have two Strings:

String a=\"org.test.A\";
String b=\"org.test.B\";

I get a class by Reflection

Class aClass = Class.forN         


        
相关标签:
4条回答
  • 2020-12-10 08:53

    You could start by reading up on dynamic proxies. Proxies do not extend classes, but they do implement interfaces which you can map on your class implementation through the invocation handler.

    0 讨论(0)
  • 2020-12-10 08:55

    Generally speaking you want to be able to create new classes (not objects) at runtime. You can use bytecode engineering or java compiler api for that.

    0 讨论(0)
  • 2020-12-10 09:03

    As said before I'd recommend to look at CGLIB but there is also javassist which is a class library for editing bytecodes...

    0 讨论(0)
  • 2020-12-10 09:07

    Apart from using a JDK dynamic proxy, which works only by interface, you can use CGLIB or javassist for extending classes at runtime.

    0 讨论(0)
提交回复
热议问题