Can I override a method / constructor using reflection in Java?

I have a class called A, and I need to create a new object of this class without calling its constructor. I want to set all my attributes through reflection.

Is it possible to override class constructor Ausing reflection?

Or is there any other way to do this?

+3
source share
2 answers

In Sun / Oracle JVm you can use Unsafe.allocateInstance(Class). Otherwise, you need to create bytecode to instantiate without calling the constructor. You can use ASM for this. You cannot create an instance without a constructor using only Reflection.

BTW: , , , . ( )

+7

, ; . , .

-1

All Articles