Are Java static calls more or less expensive than non-static calls?

前端 未结 12 2382
夕颜
夕颜 2020-11-27 11:57

Is there any performance benefit one way or another? Is it compiler/VM specific? I am using Hotspot.

12条回答
  •  南方客
    南方客 (楼主)
    2020-11-27 13:04

    Well, static calls can't be overridden (so are always candidates for inlining), and don't require any nullity checks. HotSpot does a bunch of cool optimizations for instance methods which may well negate these advantages, but they're possible reasons why a static call may be faster.

    However, that shouldn't affect your design - code in the most readable, natural way - and only worry about this sort of micro-optimization if you have just cause (which you almost never will).

提交回复
热议问题