我想創建一個全局列表,可以訪問我的包的所有類。創建全局列表對象Java
例如,下面的類創建對象
public class Class2 {
protected String one, two, three;
public void newItem(String one, String two, String three) {
this.one = one;
this.two = two;
this.three = three;
}
public String getInfo() {
return one + "," + two + "," + three;
}
我想從另一個類創建對象的Class2的列表(假設Class1.java),我想該列表可從其他類,讓我們說Class3.java。
行爲應該像數據庫一樣,其中一個類創建List和其他類讀取該列表以執行一些本地操作。
首先向我們展示您的最佳努力如何?檢查http://stackoverflow.com/help/how-to-ask – StarShine
依賴注入怎麼樣? –