我有3个不同的类(1个父类和2个子类),并且我创建了一个异构数组:
Parent[] parentArray = new Parent[9];
我想按此顺序用 3 个父对象、3 个子 1 对象和 3 个子 2 对象填充此数组。
我想知道是否有比这样做更优雅的方法:
parentArray[0] = new Parent();
parentArray[1] = new Parent();
parentArray[2] = new Parent();
parentArray[3] = new Child1();
parentArray[4] = new Child1();
....
parentArray[9] = new Child2();
谢谢!
森栏
慕桂英4014372
哔哔one
相关分类