Functional Interface
- An Interface that has only one abstract method.
- There can be default interface methods.
- There can be static methods.
- Current Examples are Runnable / Callable / Comparator
public class FunctionalInterfaceEx {
@FunctionalInterface
public interface Functional {
void method();
}
- Can replace any Functional Interface
Arrays.asList("a", "b", "d").forEach
( e -> {
System.out.print( e );
System.out.print( e );
}
);
Interface : Default Methods
- New methods added to existing Interfaces.
- Implementors need not override these.
- Evolves the interface. Current examples :
- java.util.Collection [ stream(), parallelStream(), removeIf()]
- java.util.Iterable [ forEach() ]
- java.util.List [ replaceAll() ]
private interface DefaultMethods {
default String notRequired() {
return "Default implementation";
}
}
Interface - Static MethodsMethod Referencepublic class StaticMethods { static List create(Supplier<List> supplier) { return supplier.get(); } }
- Class :: new
- Class :: static_methods
- Class :: method
- instance :: method
Repeating Annotations
@Filter( "filter1" )
@Filter( "filter2" )
public interface Filterable {
}
Better Type Inference
Extended Annotations Support
- Now, it is possible to annotate mostly everything: local variables, generic types, super-classes and implementing interfaces, even the method’s exceptions declaration
Parameter Names
- Preserve Parameters names in bytecode.
- Compile with -parameters argument [ javac Abc -parameters]
- isPresent(), get(), empty(), ofNullable(T t)
Streams - java.util.stream - Functional style programming. Collections Processing
New Date Time Library -
Nashorn JavaScript engine
Parallel Arrays
Concurrency
- Collection.stream().filter()
- Collection.stream().parallel().map(fn).reduce(fn)
- Collection.stream().mapToDouble(fn).mapToInt(fn)
- Collection.stream().serial().collect()
New Date Time Library -
- JSR 310
- Influenced by Joda-Time, Immutable
- java.time.Clock
- java.time.LocalDate
- java.time.LocalTime
- java.time.LocalDateTime
- java.time.ZonedDateTime
- java.time.Duration
- java.time.Instant
Nashorn JavaScript engine
Parallel Arrays
- parallelSetAll()
- parallelSort()
Concurrency
- New methods added to ConcurrentHashMap & ForkJoinPool
- New class - java.util.concurrent.locks.StampedLock
JVM Features - Permgen is gone
- JEP 122
- Replaced with Metaspace - Used native memory for the representation of class metadata
No comments:
Post a Comment