Lets say I have a class called Product which contains a counstructor like this
public Product(String name, double price, int barcode){
this.name = name;
this.barcode = barcode;
this.price = price;
}
I then have another class ImportData which have a method that load a lot of products into a List that returns a productList.
I now want to acces this list from different classes without have to load the data into the csv-file once again.
So instead of this:
ImportFruitAndVegatables iFV = new ImportFruitAndVegatables();
List<Product> products = iFV.fillListWithProducts();
I want something like this
mainController.products
Because my mainController already runs the method. Like this
List <Product> productList = importFruitAndVegatables.fillListWithProducts();
So my question is: Are there any way you only need to run this method once and dont need to run it again? Thank you!
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…