7段階目(instanceofで型を確認しよう)
This commit is contained in:
@@ -99,9 +99,17 @@ public class Main {
|
||||
dept[5].setNmDepartment("営業企画部");
|
||||
allData[10] = dept[5];
|
||||
|
||||
int employeeCount = 0;
|
||||
int deptCount = 0;
|
||||
for (BaseData data : allData) {
|
||||
System.out.println(data);
|
||||
if (data instanceof EmployeeData) {
|
||||
employeeCount++;
|
||||
} else if (data instanceof DepartmentData) {
|
||||
deptCount++;
|
||||
}
|
||||
}
|
||||
System.out.println("社員データ:" + employeeCount + "件\n部署データ:" + deptCount + "件");
|
||||
System.out.println();
|
||||
|
||||
//nullおよび前後の空白を取り除いた結果が空文字チェック
|
||||
|
||||
Reference in New Issue
Block a user