Search code examples
javainline

Does Java has a compiler directive to inline a method?


Has Java like other languages a directive to inline a method at compile time or at JIT time?

We have many methods that call only the super method. This make it clear that it was not forget to override the method.

For example you have override the equals methods but was use the same hashcode like super implementation. This make clear for a later developer that the hashcode method was not forget to implements. The same is also valid for setter and getter or add and remove.

But the compiler should inline this method.


Solution

  • The Java compiler does very few optimisations at compile time.

    Instead the JIT does most of the optimisations at runtime based on how the applciation is actually used. It can inline methods, even up to two "virtual" methods.