- an action to be performed on an object Function<T, R> - a function transforming a T to a R Supplier<T> - provide an instance of a T (such as a factory) UnaryOperator<T> - a function from T to T BinaryOperator<T> - a function from (T, T) to T
An instance method of a particular object (instanceRef::methName) A super method of a particular object (super::methName) An instance method of an arbitrary object of a particular type (ClassName::methName) A class constructor reference (ClassName::new) An array constructor reference (TypeName[]::new)
void foo(){} } We resolve it manually by overriding the conflicting method. Option B: public class Clazz implements A, B { public void foo(){ A.super.foo(); // or B.super.foo() } } We call the default implementation of method foo() from either interface A or B instead of implementing our own.
the iterable Collections: In order to add a default behaviour to all the iterable collections, a default forEach method was added to the Iterable<E> interface.
parameter which enables us to pass in a lambda or a method reference as follows: List<?> list = ... list.forEach(System.out::println); However, this is also valid for object of class Set<E> or Queue<E> for example, since both classes implement the Iterable interface.
lambdas and JDK libraries. However, the scope of this feature surpasses the retrocompatibility domain: they can also help reduce the amount of redudant code when dealing with libraries like Swing.
by possibly many threads is a common scalability problem. A set of new classes were created for that purpose: DoubleAccumulator DoubleAdder LongAccumulator LongAdder
all you want to do is increment a variable across threads, it was overkill and then some. These classes are usually preferable to alternatives when multiple threads update a common value that is used for purposes such as summary statistics that are frequently updated but less frequently read.
as specific subsets of the DoubleAccumulator and LongAccumulator functionality. The call new DoubleAdder() is equivalent to new DoubleAccumulator((x, y) ‐> x + y, 0.0). The call new LongAdder() is equivalent to new LongAccumulator((x, y) ‐> x + y, 0L).
generators Random random = new Random(); Stream randomNumbers = Stream.generate(random::nextInt); from other streams Stream newStream = Stream.concat(stream, randomNumbers);
match a Predicate .map - perform transformation of elements using a Function .flatMap - transform each element into zero or more elements by way of another Stream .peek - performs some action on each element .distinct - excludes all duplicate elements (equals()) .sorted - orderered elements (Comparator) .limit - maximum number of elements .substream - range (by index) of elements List persons = ...; Stream tenPersonsOver18 = persons.stream() .filter(p ‐> p.getAge() > 18) .limit(10);