Java: How will JVM optimise the call to a void and empty function?

前端 未结 6 924
囚心锁ツ
囚心锁ツ 2020-12-15 23:35

Let\'s imagine we have the following classes:

public class Message extends Object {}

public class Logger implements ILogger {
 public void log(Message m) {/         


        
6条回答
  •  余生分开走
    2020-12-16 00:21

    The Server JIT will certainly inline and eventually eliminate the code altogether if you make the reference final: final ILogger l = new Logger(); In a modern JVM most of the optimization is performed by the JIT.

提交回复
热议问题