我有問題顯示使用數組實用程序類添加到列表中的元素。值存儲是從下從列表中獲取最後一個元素不管索引
public class People {
private static Integer age;
private static String name;
public People(String name,Integer age){
this.age = age;
this.name = name;
}
public Integer getAge(){
return this.age;
}
public String getName(){
return this.name;
}
@Override
public String toString(){
return "name"+this.getName()+" Age"+ this.getAge();
}
所示的類人}
的值由下面的代碼加入到列表對象:
List<People> myPeople = Arrays.asList(
new People("Samuel Owino", 18),
new People("Swale Mdohe", 12),
new People("Joseph Wambwile", 48),
new People("Samuel Werre", 18),
new People("Swale Mdohe", 12),
new People("Joseph Wambwile", 48)
);
顯示代碼如下:
myPeople.forEach(System.out::println);
認識到問題是在實例變量上使用靜態訪問修飾符bean類,年齡和名稱,當靜態被移除時,該方法完美地工作。感謝您的參考。
那麼究竟什麼是你遇到的問題? – jeffdill2