我有一個問題,這對專家來說可能是基本問題。但我不是java專家。所以我不知道也無法在谷歌中找到很多細節。希望有人可以幫助我。我想從 Main 類中存在的方法訪問一個 List,以便在不同包中不同類的另一種方法中使用。所有訪問修飾符都是公開的。這可以在java8中訪問嗎?public class Main {public static void main(String[] args) throws IOException { initTariffData() ; .... ....}public static void initTariffData() { List<List<Object>> SlotList = null; ....... ....... for(int innerloop=0; innerloop<(CostList.size());innerloop++) { newList = new ArrayList<>(); newList.add(PowerList.get(innerloop)); newList.add(DurationsList.get(innerloop)); newList.add(CostList.get(innerloop)); SlotList.add(newList); //Lists of all slots for 7 days } }}另一堂課:public class MyModel implements TariffModel {.....//Here I want to access the List "Slotlist" from the function "initTariffData" in main class....}我希望我的問題很清楚并提供必要的信息。如果還不清楚,請告訴我。我在谷歌搜索了很多,但是關于從 Main 類中的不同方法訪問變量到另一個包類的信息并不多。
從主類中的靜態方法訪問列表,在java中不同類的另一個方法中
慕婉清6462132
2021-10-28 14:08:24