JVM/Java, are method accessibility rules enforced at runtime?

前端 未结 4 903
北恋
北恋 2021-01-06 15:44

I was curious about how the JVM works. Does the JVM acknowledge method accesibility rules like \'private\' protected or is that only done at compile time?

For examp

4条回答
  •  花落未央
    2021-01-06 16:04

    To the JLS!

    15.12.4 Runtime Evaluation of Method Invocation
    At run time, method invocation requires five steps. First, a target reference may be computed. Second, the argument expressions are evaluated. Third, the accessibility of the method to be invoked is checked. Fourth, the actual code for the method to be executed is located. Fifth, a new activation frame is created, synchronization is performed if necessary, and control is transferred to the method code.

    The wording of the JLS indicates that the accessibility would be checked at runtime.

提交回复
热议问题