Más contenido relacionado La actualidad más candente (20) Similar a What's new in java 8 (20) What's new in java 82. What’s New in Java 8
● Lambda Expression
● Default Methods
● Streams
● Optional
● Nashorn
● New Date and Time API
● No More PermGen
3. What’s New in Java 8
● Lambda Expression
● Default Methods
● Streams
● Optional
● Nashorn
● New Date and Time API
● No More PermGen
4. Java 9 has been scheduled for general
availability in 2017
8. Lambda Expression - Syntax Example
() -> { System.out.println(“Hello”); }
(int i) -> System.out.println(i)
(double d1, double d2) -> Double.compare(d1, d2)
9. Lambda Expression - Method References
A method references is the shorthand syntax
for a lambda expression that executes just one
method
10. Lambda Expression - Method References
Sometimes lambda expression is just a call to some method
list.forEach(s -> System.out.println(s));
11. Lambda Expression - Method References
You can turn that lambda expression into method reference
list.forEach(System.out::println);
12. Lambda Expression - Method References
Consumer<String> consumer = (s) -> {
System.out.println(s)
};
Consumer<String> consumer = System.out::println;
14. Default Methods
Default methods enable you to add new
functionality to the interfaces of your libraries
and ensure binary compatibility with code
written for older versions of those interfaces.
15. Default Methods - Example
public interface Iterable<T> {
Iterator<T> iterator();
default void forEach(Consumer<? super T> action) {
Objects.requireNonNull(action);
for (T t : this) { action.accept(t); }
}
default Spliterator<T> spliterator() { ... }
}
17. Static Methods - Example
public interface Vertx extends Measured {
static Vertx vertx() {
return factory.vertx();
}
...
VertxFactory factory =
ServiceHelper.loadFactory(VertxFactory.class);
}
22. Streams - Example
int sum = widgets.stream()
.filter(w -> w.getColor() == RED)
.mapToInt(w -> w.getWeight())
.sum();
23. Streams - Example
int sum = widgets.parallelStream()
.filter(w -> w.getColor() == RED)
.mapToInt(w -> w.getWeight())
.sum();