我目前正在使用SparseArray
,并希望获得其中2个不同类别的数据,这是否可能?
答案 0 :(得分:1)
你可以这样做。
interface FruitInterface { /* common methods */ }
public class Apple implements FruitInterface { }
public class Pear implements FruitInterface { }
SparseArray<FruitInterface> fruits = new SparseArray<FruitInterface>();
或者你可以这样做。
SparseArray<Object> fruits = new SparseArray<Object>();
然后检查
if (fruits.get(0) instanceof Apple) {
} else if (fruits.get(0) instanceof Pear) {
}