回答編集履歴

3

追記

2018/03/05 21:49

投稿

退会済みユーザー
test CHANGED
@@ -29,3 +29,29 @@
29
29
 
30
30
 
31
31
  がエラーになる理由と同じ
32
+
33
+
34
+
35
+ # 追記 ( 3/6 06:50 )
36
+
37
+ 少し分解してあげる・・
38
+
39
+
40
+
41
+ ```
42
+
43
+ Function<Student, Integer> function = (Student s) -> { return s.getScore();};
44
+
45
+ Collector<Student, ?, Map<Integer, List<Student>>> collector = Collectors.groupingBy(function);
46
+
47
+ Map<Integer, List<Student>> map = students.stream().collect(collector);
48
+
49
+ ```
50
+
51
+
52
+
53
+ どういう形式の Map が返されるかは2行目の Collectorで定義されています。
54
+
55
+ ソースコードをみたり、eclipse でホバーしたらどういう風に解釈されるのかとかわかると思いますよ。
56
+
57
+ Collectors.groupingBy の中身はめんどいから自分でのぞいてください。

2

a

2018/03/05 21:49

投稿

退会済みユーザー
test CHANGED
@@ -22,7 +22,7 @@
22
22
 
23
23
  Map<List<Student>, Integer> map =
24
24
 
25
- new HashMap<List<Student>, Integer>();
25
+ new HashMap<Integer,List<Student>>();
26
26
 
27
27
  ```
28
28
 

1

エラーと言ってる場所の開設に変更

2018/03/05 16:04

投稿

退会済みユーザー
test CHANGED
@@ -1 +1,31 @@
1
- ほぼ int は Integer じゃないから (オートボクシングは継承関係ではない)
1
+ ~~ほぼ int は Integer じゃないから (オートボクシングは継承関係ではない)~~
2
+
3
+
4
+
5
+ ```
6
+
7
+ Map<List<Student>, Integer> map =
8
+
9
+ students.stream().collect(Collectors.groupingBy(Student::getScore));
10
+
11
+ ```
12
+
13
+
14
+
15
+ がエラーになる理由は順序として Map<KEY,VALUE> が一致しないオブジェクトが出来上がるからですね。
16
+
17
+
18
+
19
+ つまり
20
+
21
+ ```
22
+
23
+ Map<List<Student>, Integer> map =
24
+
25
+ new HashMap<List<Student>, Integer>();
26
+
27
+ ```
28
+
29
+
30
+
31
+ がエラーになる理由と同じ