MethodHandle - What is it all about?

后端 未结 4 1935
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-04 14:15

I am studying new features of JDK 1.7 and I just can\'t get it what MethodHandle is designed for? I understand (direct) invocation of the static method (and use of Core Refl

4条回答
  •  北海茫月
    2020-12-04 14:48

    What you can do with MethodHandles is curry methods, change the types of parameters and change their order.

    Method Handles can handle both methods and fields.

    Another trick which MethodHandles do is use primitive direct (rather than via wrappers)

    MethodHandles can be faster than using reflection as there is more direct support in the JVM e.g they can be inlined. It uses the new invokedynamic instruction.

提交回复
热议问题