Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 82aee05

Browse files
unmodifiableList and unmodifiableMap beyond java 8
1 parent 6e29e1d commit 82aee05

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
package eclipse_collection;
22

33
public class Main {
4+
public static void main( String[] args ) {
5+
System.out.println("hello");
6+
}
47
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package others.youtube;
2+
3+
4+
import java.util.*;
5+
6+
/**
7+
* Life Beyond Java 8, by Trisha Gee / JetBrains Technology Day for Java (2020)
8+
* https://www.youtube.com/watch?v=gKestt55Q4M
9+
*/
10+
public class BeyondJava8 {
11+
12+
public static void main( String[] args ) {
13+
//unmodifiableList();
14+
unmodifiableMap();
15+
}
16+
17+
//creating an unmodifiableMap
18+
private static void unmodifiableMap() {
19+
final Map<String, Integer> entries = Map.ofEntries(
20+
Map.entry("A", 0),
21+
Map.entry("B", 1),
22+
Map.entry("C", 2)
23+
);
24+
entries.forEach(( s, i ) -> System.out.println(s+ " => "+ i));
25+
}
26+
27+
//will throw an unsupportedOperationException
28+
public static void unmodifiableList(){
29+
//the old way
30+
List<String> strings = Arrays.asList("A", "B");
31+
List<String> stringList = Collections.unmodifiableList(strings);
32+
stringList.set(0, "C");
33+
//the new one
34+
List<String> stringList2 = List.of("A", "B");
35+
stringList2.set(0, "C");
36+
}
37+
38+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /