这涉及到以下主题:多少次静态方法将在Java执行
https://stackoverflow.com/questions/18402564/how-do-static-methods-work
假设我在一个类(识别TestClass),其查询数据库并保存它有一个静态方法在一个静态变量中,并返回它。
public static List<MyClass> getMyData()
{
setMyDataList(getMyNewData.execute());//DB Call and assigns the result to the static variable.
return myDataList;// returns the static variable
}
在这种情况下,说A类要求TestClass.getMyData()
其获取在myDataList
数据并存储,然后B类要求TestClass.getMyData()
,将在DB中再次袭来?
每次调用某个方法时,都会调用该方法。如果将结果存储在一个变量中并只访问变量,那么它将成为每次读取的变量。 –