我想知道:靜態方法比獨立類慢嗎?
比方說,我有一個使用靜態對象做某些計算類:
public class test {
static String test = "Hello World";
public static void main(String[] args)
{
System.out.println(staticMethod());
}
static String staticMethod()
{
return test;
}
}
現在會有在計算時間差,如果我會使用另一個類,如下所示:
public class test {
static String test = "Hello World";
public static void main(String[] args)
{
System.out.println(test2.staticMethod());
}
}
import static dataConnection.test.*;
public class test2 {
static String staticMethod()
{
return test;
}
}
因此,如果我移動靜態方法變成不同的類?
我的理論是因爲Java通過指針,應該沒有區別。但編譯器不需要挖掘更多代碼,因此計算時間會增加?
謝謝!很多附加價值的當前答案。我很感激! –