Use invokedynamic to implement multiple dispatch

后端 未结 2 498
长情又很酷
长情又很酷 2021-02-06 04:29

I wondered if Java7\'s new invokedynamic bytecode instruction could be used to implement multiple dispatch for the Java language. Would the new API under java.lang.

2条回答
  •  深忆病人
    2021-02-06 05:18

    The instruction invokedynamic is purely a JVM instruction, it does not relate to dynamic dispatch. The dispatch is completed by method handles (method handle graph and method handle tree are also OK.) that comprises multiple method handle instances. A path in the graph (tree) represents one dispatch path.

    For your given sample, i would possible construct a graph (Different people might have different graph result ). IN this graph, the traverse of method handles in the graph is the way how disptach completes.

    sample method handle tree

提交回复
热议问题