Is there a runtime advantage to importing static methods vs calling the static class.method() as needed?
Example...
package com;
public class TestMain {
public static void main(String[] args) {
TestOne firstTester = new TestOne();
TestTwo secondTester = new TestTwo();
firstTester.setVars();
firstTester.setVarSum();
firstTester.printVarSum();
secondTester.setVars();
secondTester.setVarSum();
secondTester.printVarSum();
}
}
package com;
public abstract class TestSubMethods {
public static int getMethodOne(){return 1;}
public static int getMethodTwo(){return 2;}
public static int getMethodThree(){return 3;}
public static int getMethodFour(){return 4;}
}
-------------------------------------------------------------------
package com;
public class TestOne {
private int varOne;
private int varTwo;
private int varThree;
private int varFour;
private int varSum;
public void setVars() {
this.varOne = TestSubMethods.getMethodOne();
this.varTwo = TestSubMethods.getMethodTwo();
this.varThree = TestSubMethods.getMethodThree();
this.varFour = TestSubMethods.getMethodFour();
}
public void setVarSum() {
this.varSum = this.varOne + this.varTwo + this.varThree + this.varFour;
}
public void printVarSum() {
System.out.println("varSum = " + this.varSum);
}
}
-----vs-----
package com;
import static com.TestSubMethods.*;
public class TestTwo {
private int varOne;
private int varTwo;
private int varThree;
private int varFour;
private int varSum;
public void setVars() {
this.varOne = getMethodOne();
this.varTwo = getMethodTwo();
this.varThree = getMethodThree();
this.varFour = getMethodFour();
}
public void setVarSum() {
this.varSum = this.varOne + this.varTwo + this.varThree + this.varFour;
}
public void printVarSum() {
System.out.println("varSum = " + this.varSum);
}
}
Between "TestOne" and "TestTwo" Is there a preferred style? Is one a faster runtime than the other? I was going to use "extends TestSubMethods", but it was recommended I don't do this.