質問編集履歴
1
補足
test
CHANGED
File without changes
|
test
CHANGED
@@ -47,3 +47,35 @@
|
|
47
47
|
Test.add("int") // [1, "2]
|
48
48
|
|
49
49
|
```
|
50
|
+
|
51
|
+
|
52
|
+
|
53
|
+
ジェネリクスを用いて見様見真似で書いたもの
|
54
|
+
|
55
|
+
```java
|
56
|
+
|
57
|
+
public <T> List<T> add(String str) {
|
58
|
+
|
59
|
+
List<T> list = new ArrayList<>();
|
60
|
+
|
61
|
+
if(str == "string") {
|
62
|
+
|
63
|
+
list.add((T) "hoge");
|
64
|
+
|
65
|
+
list.add((T) "fuga");
|
66
|
+
|
67
|
+
}
|
68
|
+
|
69
|
+
if(str == "int") {
|
70
|
+
|
71
|
+
list.add((T) 1);
|
72
|
+
|
73
|
+
list.add((T) 2);
|
74
|
+
|
75
|
+
}
|
76
|
+
|
77
|
+
return list;
|
78
|
+
|
79
|
+
}
|
80
|
+
|
81
|
+
```
|