Mapa mental
Java8 lambdas
Contenido del mapa
Java8 lambdas
Functional References
- Class::instanceMethod
- Class::staticMethod
- object::instanceMethod
- public class User { private String name; public User(String name) { this.name = name; } public void printName() { System.out.println(name); } } public class Main { public static void main(String[] args) { User u1 = new User("AAA"); User u2 = new User("BBB"); User u3 = new User("ZZZ"); List userList = Arrays.asList(u1, u2, u3); userList.forEach(User::printName); // works userList.forEach(u1::printName); // compile error } }
- EnclosingClass.this::method
- In an inner class, you can capture the this reference of an enclosing class as EnclosingClass.this::method. You can also capture super
- Class::new
- Stream stream = names.stream().map(Employee::new); int[]::new is a constructor reference with one parameter: the length of the array. It is equivalent to the lambda expression n -> new int[n]. Employee[] buttons = stream.toArray(Employee[]::new);
Interface
- Constant Fields
- implicit public,static, final
- Default Methods
- declared using Default
- fully implemented method
- Static methods
- single abstract method makes interface functional
- Constant Fields
java.util.function
- Predicate
- BiPredicate<T,U> => boolean tes(T,U)
- Consumer<T> => void accept(T)
- Function<T,R> => R apply(T)
- ToDoubleFunction<T> => double applyAsDouble(T)
- DoubleFunction<R> => R apply(double)
- Supplier<T> => T get()
- Unary
- UnaryOperator<T> => T apply(T)
- Predicate
Lambda Operations
- filter()
- map(Function<T,R>)
- mapToLong()
- mapToInt()
- peek(Consumer<T>)
- forEach()
- count()
- sum()
- average()
- min(Comparator<T>)
- findFirst()
- findAny()
- anyMatch()
- allMatch()
- noneMatch()
- mapToDouble()
- max(Comparator<T>)
- sorted(Comparator<T>)
- Comparing(Function<T,U>)
- reversed()
- collect(Collector<?>)
- java.util.stream.Collectors
- averagingDouble(ToDoubleFunction<T>)
- groupingBy(Function<K>)
- Map<String, Long> counting = items.stream().collect( Collectors.groupingBy(Item::getName, Collectors.counting()));
- joining()
- partitioningBy(Predicate<T>)
Stream
- Collection .stream() parallelStream()
- Arrays.stream(Object[])
- Stream.of(Object[])
- intStream.range()
- Stream.iterate(Object,UnaryOperator)
- BufferedReader.lines()
Información
- Descripción
- Mapa Mental sobre Java8 lambdas, creado por Roberts Polis el 21/05/2017.
- Creado por
- Roberts Polis
- Visitas
- 6
- Valoración