Failure Sharing

Bootup your energy with sharing failure.

Lambda Summary

Functional Interface

@FunctionalInterface
public interface InnerApp {
    public void func(); // 이 줄만 정의되어 있다면 static, default 등 다른 무엇이 정의되어 있어도 함수형 인터페이스로서 인정.
    public static void test() {}
}

타입 지정 하고 안하고의 차이

Portable<Integer> p = (Integer n) -> syso(n);

// equals

Portable p = n -> syso(n);

種類

  1. Function<T, R> R apply (T t)
  2. Consumer void accept(T t)
  3. Predicate boolean test(T t)
  4. Supplier get() ... no parameter

  5. BiFunction<T, U, R> R apply (T t, U u)

Bi로 시작하면 다 인수가 2개네.

UnaryOperator

인수와 결과값의 데이터타입이 같다.

UnaryOperator<T>  T apply (T t)
// Compile Error!!
        List<Integer> codes = Arrays.asList(10, 20);
        UnaryOperator<Double> uo = s -> s + 10.0;
        codes.replaceAll(uo);

Method reference

클래스명 또는 참조변수명::메소드명

//Same
        Function<String, Integer> f = t -> t.length();
        Function<String, Integer> f1 = String::length;

Arrays.sort(array, ValueCheck::checkDef)

static메소드의 경우 new가 필요하지 않다. 1) static : 클래스명::메소드명 2) non-static : 클래스명::new::메소드명

replaceAll(UnaryOperator operator)

변환 후 재 설정

ToIntFunction ... int applyAsInt(T value)

        String str = "I am a Java developer";
        ToIntFunction<String> index = str::indexOf; // == str.indexOf(value);
        int x = index.applyAsInt("Java");
        System.out.println(x);

Initialization

Edisble meal = Food::new; // == name -> new Food(name);