Why does the Java compiler 11 use invokevirtual to call private methods?
45
3
When compiling the code below with the Java compiler from OpenJDK 8, the call to foo() is done via an invokespecial , but when OpenJDK 11 is used, an invokevirtual is emitted. public class Invoke { public void call() { foo(); } private void foo() {} } Output of javap -v -p when javac 1.8.0_282 is used: public void call(); descriptor: ()V flags: (0x0001) ACC_PUBLIC Code: stack=1, locals=1, args_size=1 0: aload_0 1: invokespecial #2 // Method foo:()V 4: return Output of javap -v -p when javac 11.0.10 is used: public void call(); descriptor: ()V flags: (0x0001) ACC_PUBLIC Code: stack=1, locals=1, args_size=1 0: aload_0 1: invokevirtual #2 // Method foo:...