Is it correct to assume that calling a static method is fast compared to the allocating and garbage collecting an integer?
Or, in other words would either fh1 or fh2 be preferable? In fh1 allocation is avoided but fh2 seems simpler. In this case the G.f() is a relatively simple method which will be called often. fh2 and fh1 will also be called often (potentially as many as 30 times per second).
Pseudo Code:
class G {
static method int f() {.......}
}
class H {
method fh1(){
somemethod1(G.f());
somemethod2(G.f());
somemethod3(G.f());
}
method fh2(){
int a = G.f();
somemethod1(a);
somemethod2(b);
.....
}
}