in c and c++ we have macro and inline functions.
In java u can not override final methods but My query is
Does in java final methods wroks like inline methods ?
Inline means the method call is replaced by method body at compile time so logically it improves the performance.
I would like to know if final method works like an inkine method up to what extend it really improves the performance.
Thanks in advance
In addition, Hotspot can inline methods that are public and non-final. If Hotspot can determine that a method is not overridden, it might decide to inline it. At a later time, if a class is dynamically loaded that overrides that public method, Hotspot will un-inline the method to ensure the proper behavior of the program.
Senior Software Engineer, IBM
author of: Practical Java
Originally posted by Peter Haggar:
... The runtime optimizer (Jit or Hotspot) will inline a method based on different factors. final is just one of those factors. However, because a method is final, does not guarantee that it will ever be inlined. It simply makes it a potential candidate for inlining.
Also, note that same applies to inline in C++. Method declared inline may not be inlined by the compiler. It simply makes it a potential candidate for inlining.