8段階目(キャストでサブクラス限定の機能を使おう)

This commit is contained in:
s-sakiyama
2026-09-16 16:17:23 +09:00
parent 08b99dc55b
commit 0ac701ce98

View File

@@ -112,14 +112,26 @@ public class Main {
System.out.println("社員データ:" + employeeCount + "件\n部署データ:" + deptCount + "件"); System.out.println("社員データ:" + employeeCount + "件\n部署データ:" + deptCount + "件");
System.out.println(); System.out.println();
//nullおよび前後の空白を取り除いた結果が空文字チェック System.out.println("メールアドレス表示");
// BaseData emp = new EmployeeData("10000", "デフォルト", "ヤマダタツヤ", "yamada@hoge.jp", "aaa", "10"); for (BaseData data : allData) {
// System.out.println(emp); if (data instanceof EmployeeData) {
// (EmployeeData)emp.setNmEmployee(null); System.out.println(((EmployeeData) data).getMailAddress());
// System.out.println(emp); }
// emp.setNmEmployee("   "); }
// System.out.println(emp);
System.out.println();
//nullおよび前後の空白を取り除いた結果が空文字チェック
BaseData emp = new EmployeeData("10000", "デフォルト", "ヤマダタツヤ", "yamada@hoge.jp", "aaa", "10");
System.out.println(emp);
((EmployeeData) emp).setNmEmployee(null);
System.out.println(emp);
((EmployeeData) emp).setNmEmployee("   ");
System.out.println(emp);
System.out.println();
System.out.println("コンストラクタに全てから文字で");
BaseData emptyEmployee = new EmployeeData("", "", "", "", "", ""); BaseData emptyEmployee = new EmployeeData("", "", "", "", "", "");
System.out.println(emptyEmployee); System.out.println(emptyEmployee);