回答編集履歴

2

typo

2022/04/20 02:09

投稿

shiketa
shiketa

スコア3971

test CHANGED
@@ -2,11 +2,11 @@
2
2
  まず、Test1DtoとTest2Dtoを同様に扱いたいのであれば、インタフェースは必要でしょう。
3
3
 
4
4
  ```java
5
- static interface TestInterface {
5
+ interface TestInterface {
6
6
  String getUserId();
7
7
  }
8
8
 
9
- public static class Test1Dto implements TestInterface {
9
+ public class Test1Dto implements TestInterface {
10
10
  private String userId;
11
11
  private String userName;
12
12
  private String address;
@@ -14,7 +14,7 @@
14
14
  @Override public String getUserId() { return userId; }
15
15
  }
16
16
 
17
- public static class Test2Dto implements TestInterface {
17
+ public class Test2Dto implements TestInterface {
18
18
  private String userId;
19
19
  private String userName;
20
20
  private String address;
@@ -46,7 +46,7 @@
46
46
  Test1Dto test1Dto = null;
47
47
  Test2Dto test2Dto = null;
48
48
 
49
- TestInterface dto = test1Dto == null ? test2Dto : test1Dto
49
+ TestInterface dto = test1Dto == null ? test2Dto : test1Dto;
50
50
 
51
51
  String userId = dto.getUserId();
52
52
  }

1

typo

2022/04/20 02:05

投稿

shiketa
shiketa

スコア3971

test CHANGED
@@ -27,7 +27,7 @@
27
27
 
28
28
  > 三項演算子以外に、上記の冗長なコードを回避する方法はありますでしょうか?
29
29
 
30
- 参考演算子が嫌いなら、こうするかな。
30
+ 三項演算子がどうしても嫌いなら、こうするかな。
31
31
 
32
32
  ```java
33
33
  private void hoge() {