Is it an example of inlining?
final class Executive extends Manager
{
public raiseSalary(int byPercent)
{
return salary;
}
}
Is it an example of inlining?
final class Executive extends Manager
{
public raiseSalary(int byPercent)
{
return salary;
}
}
Is it an example of inlining?
No, it's not.
Is there any relation between final keyword and Inlining?
Kind of. Read this:
Contrary to the implication of many tips, methods declared as final cannot be safely inlined by the compiler, because the method could have a non-final declaration at runtime.
To see why, suppose the compiler looks at class A and subclass B, and sub-subclass C and sees a final method in A which it inlines into C. But then at runtime the versions loaded for A and B are different and the method is not final in A, and overridden in B. Then C uses the incorrectly inlined version.
No, that it's not 'Inlining'.
Inlining is when the compiler decide to replace your function call with the body of the function.
Read here for full example https://stackoverflow.com/a/3925068/3743987
Java compiler does not inline final classes or methods. You can check this article.
As I know, inlining is applied to primitive constant statements. For example, the Java compiler replaces all the occurrences of MY_NUMBER
constant below with 10 during the compilation phase. Therefor, at runtime, Java does not need to make memory access to read the value of MY_NUMBER
.
private static final int MY_NUMBER = 10;