-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJava7Features.java
More file actions
38 lines (32 loc) · 1.17 KB
/
Java7Features.java
File metadata and controls
38 lines (32 loc) · 1.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package com.learn.java;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.util.stream.Stream;
public class Java7Features implements AutoCloseable {
public static void main(String[] args) {
//==========/ Multi-cast Exception /===========
try {
var x = 1 / 2;
} catch (NumberFormatException | NullPointerException ex) {
System.out.println(ex.getMessage());
}
//===========/ Try with resource /===================
try (BufferedReader reader = new BufferedReader(new FileReader(new File("path")))) {
System.out.println("");
} catch (Exception ex) {
System.out.println(ex.getMessage());
}
try (Java7Features x = new Java7Features()) {
System.out.println(x.toString());
} catch (Exception ex) {
System.out.println(ex.getMessage());
}
var result = Stream.of("Pham", "The", "Hung").reduce("", (x, y) -> x + " " + y).trim();
System.out.println(result);
}
@Override
public void close() {
System.out.println("Custom finally of try..with..resource");
}
}