My assumption is that, with compiler optimization (e.g., inlining), it makes practically no difference whether a method is "nested" a few levels. Would that be the case indeed?
For example, say that the following 3 classes are declared:
public class Third extends Second
{
public int test3() // Call test2() and nothing else
{
return super.test2();
}
}
public class Second extends First
{
public int test2()
{
return super.test1(); // Call test1() and nothing else
}
}
public class First
{
public int test1() // Calculate a result somehow
{
int result = 0;
...
return result;
}
}
Given 3 already instantiated objects third
, second
and first
, is the cost of the following calls practically the same?
third.test3();
third.test2();
third.test1();
second.test2();
second.test1();
first.test1();
Would it make any difference in optimization if the name of the method was the same?