Are static methods in Java always resolved at compile time?

前端 未结 3 1461
感情败类
感情败类 2021-01-05 01:32

Are static methods in Java always resolved at compile time?

3条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-01-05 02:16

    Yes, it is thoroughly investigated and explained in this thread on Sun's forums: New To Java - No late binding for static methods

    Several quotes:

    When the compiler compiles that class it decides at compile time which exact method is called for each static method call (that's the big difference to non-static method calls: the exact method to be called is only decided at runtime in those cases).

    Calling static methods only ever depends on the compile-time type on which it is called.

提交回复
热议问题