5.4.6 Method Selection

During execution of an invokeinterface or invokevirtual instruction, a method is selected with respect to (i) the run-time type of the object on the stack, and (ii) a method that was previously resolved by the instruction. The rules to select a method with respect to a class or interface C and a method mR are as follows:

  • If mR is marked ACC_PRIVATE, then it is the selected method.

  • Otherwise, the selected method is determined by the following lookup procedure:

    • If C contains a declaration of an instance method m that can override mR (§5.4.5), then m is the selected method.

    • Otherwise, if C has a superclass, a search for a declaration of an instance method that can override mR is performed, starting with the direct superclass of C and continuing with the direct superclass of that class, and so forth, until a method is found or no further superclasses exist. If a method is found, it is the selected method.

    • Otherwise, the maximally-specific superinterface methods of C are determined (§5.4.3.3). If exactly one matches mR’s name and descriptor and is not abstract, then it is the selected method. Any maximally-specific superinterface method selected in this step can override mR; there is no need to check this explicitly. While C will typically be a class, it may be an interface when these rules are applied during preparation (§5.4.2).

贡献翻译,请加 QQ: 840750575    点击这里给我发消息
数码
沪ICP备19006215号-4