質問編集履歴
9
総称型Lを利用しているインターフェースを追記
test
CHANGED
File without changes
|
test
CHANGED
@@ -48,6 +48,60 @@
|
|
48
48
|
|
49
49
|
|
50
50
|
|
51
|
+
/**
|
52
|
+
|
53
|
+
* Bar<E>の要素をフィルターする。
|
54
|
+
|
55
|
+
* ※質問の趣旨とは直接関係なし
|
56
|
+
|
57
|
+
*/
|
58
|
+
|
59
|
+
public Org<E> filter(final Predicate<E> filter) {
|
60
|
+
|
61
|
+
/* ロジックを簡略 */
|
62
|
+
|
63
|
+
return this;
|
64
|
+
|
65
|
+
}
|
66
|
+
|
67
|
+
|
68
|
+
|
69
|
+
/**
|
70
|
+
|
71
|
+
* Bar<E>の重複する要素を削除する。
|
72
|
+
|
73
|
+
* ※質問の趣旨とは直接関係なし
|
74
|
+
|
75
|
+
*/
|
76
|
+
|
77
|
+
public <K> Org<E> distinct(final Function<E,K> keySelector) {
|
78
|
+
|
79
|
+
/* ロジックを簡略 */
|
80
|
+
|
81
|
+
return this;
|
82
|
+
|
83
|
+
}
|
84
|
+
|
85
|
+
|
86
|
+
|
87
|
+
/**
|
88
|
+
|
89
|
+
* Bar<E>の要素を昇順に並べる。
|
90
|
+
|
91
|
+
* ※質問の趣旨とは直接関係なし
|
92
|
+
|
93
|
+
*/
|
94
|
+
|
95
|
+
public Org<E> orderBy(final Function<E, Integer> keySelector) {
|
96
|
+
|
97
|
+
/* ロジックを簡略 */
|
98
|
+
|
99
|
+
return this;
|
100
|
+
|
101
|
+
}
|
102
|
+
|
103
|
+
|
104
|
+
|
51
105
|
}
|
52
106
|
|
53
107
|
```
|
@@ -108,6 +162,8 @@
|
|
108
162
|
|
109
163
|
* Bar<E>の要素をフィルターする。
|
110
164
|
|
165
|
+
* ※質問の趣旨とは直接関係なし
|
166
|
+
|
111
167
|
*/
|
112
168
|
|
113
169
|
default L filter(final Predicate<E> filter) {
|
@@ -124,6 +180,8 @@
|
|
124
180
|
|
125
181
|
* Bar<E>の重複する要素を削除する。
|
126
182
|
|
183
|
+
* ※質問の趣旨とは直接関係なし
|
184
|
+
|
127
185
|
*/
|
128
186
|
|
129
187
|
default <K> L distinct(final Function<E,K> keySelector) {
|
@@ -140,6 +198,8 @@
|
|
140
198
|
|
141
199
|
* Bar<E>の要素を昇順に並べる。
|
142
200
|
|
201
|
+
* ※質問の趣旨とは直接関係なし
|
202
|
+
|
143
203
|
*/
|
144
204
|
|
145
205
|
default L orderBy(final Function<E, Integer> keySelector) {
|
8
総称型Lを利用しているインターフェースを追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -104,6 +104,54 @@
|
|
104
104
|
|
105
105
|
|
106
106
|
|
107
|
+
/**
|
108
|
+
|
109
|
+
* Bar<E>の要素をフィルターする。
|
110
|
+
|
111
|
+
*/
|
112
|
+
|
113
|
+
default L filter(final Predicate<E> filter) {
|
114
|
+
|
115
|
+
/* ロジックを簡略 */
|
116
|
+
|
117
|
+
return (L) this;
|
118
|
+
|
119
|
+
}
|
120
|
+
|
121
|
+
|
122
|
+
|
123
|
+
/**
|
124
|
+
|
125
|
+
* Bar<E>の重複する要素を削除する。
|
126
|
+
|
127
|
+
*/
|
128
|
+
|
129
|
+
default <K> L distinct(final Function<E,K> keySelector) {
|
130
|
+
|
131
|
+
/* ロジックを簡略 */
|
132
|
+
|
133
|
+
return (L) this;
|
134
|
+
|
135
|
+
}
|
136
|
+
|
137
|
+
|
138
|
+
|
139
|
+
/**
|
140
|
+
|
141
|
+
* Bar<E>の要素を昇順に並べる。
|
142
|
+
|
143
|
+
*/
|
144
|
+
|
145
|
+
default L orderBy(final Function<E, Integer> keySelector) {
|
146
|
+
|
147
|
+
/* ロジックを簡略 */
|
148
|
+
|
149
|
+
return (L) this;
|
150
|
+
|
151
|
+
}
|
152
|
+
|
153
|
+
|
154
|
+
|
107
155
|
}
|
108
156
|
|
109
157
|
|
7
コンパイルエラーのキャプチャを追加。
test
CHANGED
File without changes
|
test
CHANGED
@@ -216,11 +216,9 @@
|
|
216
216
|
|
217
217
|
```
|
218
218
|
|
219
|
-
|
219
|
+
>
|
220
|
-
|
220
|
+
|
221
|
-
![イメージ説明](
|
221
|
+
![イメージ説明](7e34d6a5a7218ef236244b8b939fb1a7.png)
|
222
|
-
|
223
|
-
---
|
224
222
|
|
225
223
|
|
226
224
|
|
6
コンパイルエラーのキャプチャを追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -216,6 +216,12 @@
|
|
216
216
|
|
217
217
|
```
|
218
218
|
|
219
|
+
---
|
220
|
+
|
221
|
+
![イメージ説明](b1ea4873314d5c8ac6323dc696321809.png)
|
222
|
+
|
223
|
+
---
|
224
|
+
|
219
225
|
|
220
226
|
|
221
227
|
###ご質問
|
5
質問文を小修整
test
CHANGED
File without changes
|
test
CHANGED
@@ -172,7 +172,7 @@
|
|
172
172
|
|
173
173
|
try {
|
174
174
|
|
175
|
-
// このケースは問題なく動作する。
|
175
|
+
// (1)このケースは問題なく動作する。
|
176
176
|
|
177
177
|
Bar<String> strBar = new Bar<>(...);
|
178
178
|
|
@@ -180,7 +180,7 @@
|
|
180
180
|
|
181
181
|
|
182
182
|
|
183
|
-
// このケースはコンパイルエラー
|
183
|
+
// (2)このケースはコンパイルエラー
|
184
184
|
|
185
185
|
Foo<Foo<String>> strFooFoo = new Foo<>(...);
|
186
186
|
|
@@ -188,15 +188,15 @@
|
|
188
188
|
|
189
189
|
|
190
190
|
|
191
|
-
// このケースは問題なく動作するが、こんな書き方をさせたくない
|
191
|
+
// (3)このケースは問題なく動作するが、こんな書き方をさせたくない
|
192
192
|
|
193
193
|
Foo<Foo<String>> strFooFoo2 = new Foo<>(...);
|
194
194
|
|
195
|
-
Foo<Foo<Integer>> intFooFoo2 = strFooFoo2.map(foo -> foo.<Integer, Foo<Integer>>map(item -> item.length()));
|
195
|
+
Foo<Foo<Integer>> intFooFoo2 = strFooFoo2.<Foo<Integer>, Foo<Foo<Integer>>>map(foo -> foo.<Integer, Foo<Integer>>map(item -> item.length()));
|
196
|
-
|
197
|
-
|
198
|
-
|
196
|
+
|
197
|
+
|
198
|
+
|
199
|
-
// オリジナルのクラスでも、問題なく動作する。
|
199
|
+
// (4)オリジナルのクラスでも、問題なく動作する。
|
200
200
|
|
201
201
|
Org<Org<String>> strOrgOrg = new Org<>(...);
|
202
202
|
|
@@ -220,7 +220,7 @@
|
|
220
220
|
|
221
221
|
###ご質問
|
222
222
|
|
223
|
-
「型の不一致」エラーが出ている
|
223
|
+
「型の不一致」エラーが出ている(2)について、
|
224
224
|
|
225
225
|
ソースコード側ではなく、IBarインターフェース側に何らかの手を加えて、コンパイルエラーを解消できないでしょか?
|
226
226
|
|
4
質問文を小修整
test
CHANGED
File without changes
|
test
CHANGED
@@ -196,6 +196,14 @@
|
|
196
196
|
|
197
197
|
|
198
198
|
|
199
|
+
// オリジナルのクラスでも、問題なく動作する。
|
200
|
+
|
201
|
+
Org<Org<String>> strOrgOrg = new Org<>(...);
|
202
|
+
|
203
|
+
Org<Org<Integer>> intOrgOrg = strOrgOrg.map(org -> org.map(item -> item.length()));
|
204
|
+
|
205
|
+
|
206
|
+
|
199
207
|
}
|
200
208
|
|
201
209
|
catch (Exception e) {
|
3
質問文を小修整
test
CHANGED
File without changes
|
test
CHANGED
@@ -172,7 +172,7 @@
|
|
172
172
|
|
173
173
|
try {
|
174
174
|
|
175
|
-
// このケースは問題する。
|
175
|
+
// このケースは問題なく動作する。
|
176
176
|
|
177
177
|
Bar<String> strBar = new Bar<>(...);
|
178
178
|
|
@@ -188,7 +188,7 @@
|
|
188
188
|
|
189
189
|
|
190
190
|
|
191
|
-
// このケースは
|
191
|
+
// このケースは問題なく動作するが、こんな書き方をさせたくない
|
192
192
|
|
193
193
|
Foo<Foo<String>> strFooFoo2 = new Foo<>(...);
|
194
194
|
|
2
質問文を小修整
test
CHANGED
File without changes
|
test
CHANGED
@@ -50,7 +50,9 @@
|
|
50
50
|
|
51
51
|
}
|
52
52
|
|
53
|
-
|
53
|
+
```
|
54
|
+
|
55
|
+
```java
|
54
56
|
|
55
57
|
/**
|
56
58
|
|
@@ -210,6 +212,8 @@
|
|
210
212
|
|
211
213
|
###ご質問
|
212
214
|
|
215
|
+
「型の不一致」エラーが出ている行について、
|
216
|
+
|
213
217
|
ソースコード側ではなく、IBarインターフェース側に何らかの手を加えて、コンパイルエラーを解消できないでしょか?
|
214
218
|
|
215
219
|
|
1
コンパイルエラーが出ないケースを追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -70,19 +70,33 @@
|
|
70
70
|
|
71
71
|
*/
|
72
72
|
|
73
|
+
default
|
74
|
+
|
75
|
+
<O, OL extends IBar<O, OL>>
|
76
|
+
|
73
|
-
|
77
|
+
OL map(final Function<E,O> mapper){
|
78
|
+
|
74
|
-
|
79
|
+
try {
|
80
|
+
|
75
|
-
Constructor<OL> con = (Constructor<OL>) this.getClass().getConstructor();
|
81
|
+
Constructor<OL> con = (Constructor<OL>) this.getClass().getConstructor();
|
76
|
-
|
82
|
+
|
77
|
-
OL ol = con.newInstance();
|
83
|
+
OL ol = con.newInstance();
|
78
|
-
|
79
|
-
|
80
|
-
|
84
|
+
|
85
|
+
|
86
|
+
|
81
|
-
this.stream().map(mapper).forEach(value -> ol.add(value));
|
87
|
+
this.stream().map(mapper).forEach(value -> ol.add(value));
|
82
|
-
|
83
|
-
|
84
|
-
|
88
|
+
|
89
|
+
|
90
|
+
|
85
|
-
return ol;
|
91
|
+
return ol;
|
92
|
+
|
93
|
+
}
|
94
|
+
|
95
|
+
catch (Exception e) {
|
96
|
+
|
97
|
+
return null;
|
98
|
+
|
99
|
+
}
|
86
100
|
|
87
101
|
}
|
88
102
|
|
@@ -124,7 +138,7 @@
|
|
124
138
|
|
125
139
|
extends java.util.LinkedList<E>
|
126
140
|
|
127
|
-
implements IBar<E,
|
141
|
+
implements IBar<E, Foo<E>> {
|
128
142
|
|
129
143
|
/**
|
130
144
|
|
@@ -156,9 +170,9 @@
|
|
156
170
|
|
157
171
|
try {
|
158
172
|
|
159
|
-
// このケースは問題
|
173
|
+
// このケースは問題する。
|
160
|
-
|
174
|
+
|
161
|
-
Bar<String> strBar = new Bar<>();
|
175
|
+
Bar<String> strBar = new Bar<>(...);
|
162
176
|
|
163
177
|
Bar<Integer> intBar = strBar.map(item -> item.length());
|
164
178
|
|
@@ -166,12 +180,20 @@
|
|
166
180
|
|
167
181
|
// このケースはコンパイルエラー
|
168
182
|
|
169
|
-
Foo<Foo<String>> strFooFoo = new Foo<>();
|
183
|
+
Foo<Foo<String>> strFooFoo = new Foo<>(...);
|
170
184
|
|
171
185
|
Foo<Foo<Integer>> intFooFoo = strFooFoo.map(bar -> bar.map(item -> item.length())); /* 型の不一致! */
|
172
186
|
|
173
187
|
|
174
188
|
|
189
|
+
// このケースはコンパイルエラーにならず動作するが、こんな書き方をさせたくない
|
190
|
+
|
191
|
+
Foo<Foo<String>> strFooFoo2 = new Foo<>(...);
|
192
|
+
|
193
|
+
Foo<Foo<Integer>> intFooFoo2 = strFooFoo2.map(foo -> foo.<Integer, Foo<Integer>>map(item -> item.length()));
|
194
|
+
|
195
|
+
|
196
|
+
|
175
197
|
}
|
176
198
|
|
177
199
|
catch (Exception e) {
|