Vous êtes sur la page 1sur 2

Java 8 Pluralsight

One can put modifiers on the parameters of a lambda expression (final)


It is not possible to specify the returned type of a lambda expression
We can also omit the types of the parameters
Method references => another way of writing lambda expression
Lambda Expression is an anonymous function which accepts a set of
input parameters and returns a result. It is an instance of a functional
interface
Lambda Expression contains 3 parts:
o Parameter List (parameters are optional)
o Lambda arrow operator, -> separates parameters list and body
o Lambda expression body
Functional Interface is an interface which contains one and only one
abstract method. Default method do not count! Static methods do
not count! Methods from the Object class do not count!for
ex( equals) Default method from Object class are not allowed (for
ex default hashcode ). Annotation @FunctionalInterface is not
mandatory
SAM= single abstract method interface. Only one abstract method
Optional: it can contain either one value or zero value. It is used to avoid
null checks and to avoid null pointer exception
Type Inference means determining the Type by compiler at compile-time. It
is not new in Java 8, but has been enhanced
The type of the variable gives the type of the lambda expression
Java.util.function package: 1. The Consumers, 2. The Supplier, 3. The
Functions, 4. The Predicates
The consumers: consumes an object and does not return anything
The Supplier: provides an object, takes no parameter
The Function: takes an object and returns another object
The Predicates: takes an object and returns a Boolean
Functional Interfaces for Primitive Type: IntPredicate, IntFunction,
IntToDoubleFunction
A stream is a typed interface, does not hold any data, it pulls the data it
processes from a source.
A stream does not modify the data it processes. The amount of elements is
not known
The map() call can change the type of a stream
The filter() call does not change the type of a stream
The peek() call can be used for logging purpose. Its an intermediate
operation
Terminal operation vs Intermediate Call. A terminal operation must be
called to trigger the processing of a Stream.
A call that returns a Stream is an intermediate call. A call that returns
something else, or void is a terminal call that triggers the processing
Stream: skip and limit;
There are two types of find reduction: findFirst(), findAny()=> they can
return an Optional if dont find result

Streams

A sequence of elements on which one or more operations can be


performed
Filter accepts a predicate to filter all elements of the stream
Sorted returns a sorted view of the stream. The elements are sorted in a
natural order unless you pass a Comparator
Map- converts each element into another object via the given function. You
can use it also to transform each object into another type. The generic
type of the resulting stream depends on the generic type of the function
you pass to map.
Match various matching operations can be used to check whether a
certain predicate matches the stream. All those operations are terminal
and return a Boolean result.
Count is a terminal operation returning the number of elements in the
stream as a long
Reduce performs a reduction on the elements of the stream with the
given function. The result is an Optional holding the reduced value.