The callback functions by anonymous class is a common approach when we use a framework or a library, so it is very useful to know if the JIT performs such kind optimizations.
I am wondering if the JIT compiler is smart enough to understand that them some code is executed every time and compile into native?
Like any other piece of code, it will be compiled and optimized by the JIT compiler once it has been executed enough times (by default, 10000 with the Hotspot server VM, 1500 with the client VM), so the JIT has enough data to base its optimizations on.
Just because it's anonymous does not mean it's treated any different: it's still a class, with a name generated during the compilation (MyClass$1).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With