java - 将子对象添加到父对象列表并获取属性
问题描述
请考虑这种情况
abstract class Human{
String ID;
String demographic;
int knoledgeSpreadSpeed;
}
class Student extends Human {
private Human connectedTo;
private final String connectionAddress;
public Student(String ID, String demographic, int knoledgeSpreadSpeed, String connectionAddress) {
super(ID, demographic, knoledgeSpreadSpeed);
this.connectionAddress = connectionAddress;
}
}
class Professor extends Human{
private int numberOfAvailableMentoringSlots;
private static HashMap<String, Human> socialConnections = new HashMap<>();
public Professor(String ID, String demographic, int knoledgeSpreadSpeed, int numberOfAvailableMentoringSlots) {
super(ID, demographic, knoledgeSpreadSpeed);
this.numberOfAvailableMentoringSlots = numberOfAvailableMentoringSlo;
}
}
List <Human> humans = new ArrayList<>();
{
humas.add(new Stunet(...));
humans.add(new Proffessor(....));
}
当我查看人员列表时,我想获取学生的通信地址
这是我尝试过的
for(Student student : humans){
student.get(comminicationAddress)
}
如何通过循环人类列表来获取学生的属性?
解决方案
推荐阅读
- c# - TreeView - 编辑时默认行为不起作用
- python - 使用 JSON 正文,而不是表单数据
- react-native - React Native透明,剪裁边框半径?
- arrays - 如何检查 Kotlin 函数中的泛型类型?
- java - android Visualizer getWaveForm(字节[]波形)总是返回-128
- sql-server - SQL Server 中的查询优化
- c# - 具有 INotifyPropertyChanged 的复合模型 - PostSharp 代表来自子模型的更改
- linux - automake native:oe_runmake 在 yocto krogoth 中失败
- javascript - Sweetalert2 allowOutsideClick 在吐司模式下不起作用,并且右侧没有出现关闭按钮
- android - WebRTC-Android:停止视频通话时如何关闭音频