I have a question which may sound as basic question to experts. But I not an expert in java. So I am not knowing and unable to find much details also in google regarding this. Hope someone can help me out.
I want to access one List from a method which is present inside Main class to use in another method of different class in a different package. All access modifiers are public. Is this possible to access in 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
}
}
}
Another class :
public class MyModel implements TariffModel {
.....
//Here I want to access the List "Slotlist" from the function "initTariffData" in main class
....
}
I hope my question is clear and providing the necessary information. Please let me know if it is still not clear.
I have searched in google so much but there is not much information regarding accessing a variable from different method inside Main class to another package class.
> SlotList = null; } public class MyModel implements TariffModel { Main.SlotList.get(2); .... } Thanks a lot!! :)
– Priya Oct 05 '18 at 09:46