0

Suppose we have object field of class java.lang.reflect.Field. It is possible to change value of that field of object o1 to the value of o2`s field by field.set(o1, o2). I am wondering whether it can be done faster with the help of some library, for example cglib?

1 Answers1

0

No, the JVM implements a JIT compiler which makes byte code generation obsolete for performance in 99.9% of the cases. In the case of reflection, people sometime use code generation to avoid the security checks that the reflection API implies. Rather than that, you should look into MethodHandles which moves this security check to the handle creation such that it is not triggered on each call.

Rafael Winterhalter
  • 42,759
  • 13
  • 108
  • 192