-
Notifications
You must be signed in to change notification settings - Fork 0
Java 9
Ondrej Kucera edited this page Dec 5, 2017
·
13 revisions
- interface private methods - you can write helpers for more classes, but they won't be public
interface Util {
default int getNumber() { return helper(); }
private int helper() { return 4; }
}
- effectively final in try-with-resources => use AutoCloseable for a class that is used in try-catch when we leave the scope on try-catch. Then the close method is automatically called. (can be dangerous!)
class Resource implements AutoCloseable {
public void foo() { ... };
public void close() { ... };
}
public static Sample {
Resource resource = new Resource();
try(resource) {
resource.method();
}
-
No _ - underscore is not available as a name of variable
IntStream.iterate(0, i -> i + 2)
.takeWhile(i -> i <= 5)
.forEach(System.out::println);
- Optional: ifPresentOrElse, or
Optional<Integer> first =
number.stream()
.filter(e -> e > 50)
.findFirst()
.or(() -> Optional.of(77));