-1
爲什麼我需要重寫繼承某些類時返回泛型類如ArrayList
的泛型方法?糾正我,如果我錯了,但對於像ArrayList這樣的泛型類,它看起來像是多餘的和不必要的。爲什麼有必要重寫Android上的Recycler類中的getData()?
public class Data {
public static ArrayList<Information> getData() {
ArrayList<Information> data = new ArrayList<>();
int[] images = {R.drawable.img_1,R.drawable.img_2,R.drawable.img_3};
String[] text = {"image_1", "image_2", "image_3"};
for (int i = 0; i < images.length; i++) {
Information current = new Information();
current.imageId = images[i];
current.title = text[i];
data.add(current);
}
return data;
}
}
public class Information {
public int imageId;
public String title;
}
它是模型POJO。它包含您在回收視圖中顯示的數據\ –
已編輯以嘗試清除不明確的措辭。也認爲這個問題可能不清楚這個概念。 – clearlight