要引用数组中的特定对象,我需要将int转换为其类型,否则编译器不接受,为什么我需要此转换?
示例:
Person[] people = Person[5]; //Generic Array of specific objects
Employee employee1 = new Employee(); //Employee class extends Person
Manager manager1 = new Manager(); //Manager class extends Person
people[0] = employee1;
people[1] = manager1;
Person ref = people[0]; //OK! it can compile
Employee ref2 = people[1]; //Do not compile
Employee ref2 = (Employee) people[1]; //OK! it can compile
为什么需要演员阵容?
小唯快跑啊
慕标琳琳
倚天杖
哔哔one
白衣非少年
相关分类