如何创建不同类型的数组?如果每个类都是该类的扩展_object
,我可以只制作一个_object
数组并将扩展添加到其中吗?
例子:
class _object {
int type = 1;
public _object() {
type = 2;
}
public doSomething() {
}
}
class tree extends _object {
public tree() {
}
}
class apple extends _object {
public apple() {
}
}
public tree aTree = new tree();
public apple anApple = new apple();
public _object[] objects = new _object[] { aTree, anApple };