메서드 참조(Method Reference)

NOAH·2021년 1월 19일
0
post-thumbnail

메서드 참조(Method Reference)

무엇? 람다식을 간단히 한 것이다.

어떻게? 클래스이름::메서드

//람다식
Function<String, Integer> f = (String s) -> Interger.parseInt(s); 

//메서드 참조
Function<String, Integer> f = Interger::Parseint

System.out.println(f.apply("100");


---  output ---
100
--- --- --- --- ---

생성자의 메서드 호출

무엇? 생성자를 호출하는 람다식을 간단힌 한 것

어떻게 ? 클래스::생성자

//Function<Integer, MyClass> f = (i) -> new MyClass(i);
Function<Integer, MyClass> f = MyClass::new ; 

//BiFunction<Integer, String, MyClass> bf = (i, s) -> new MyClass(i,s);
BiFunction<Integer, String, MyClass> bf2 = MyClass::new;


//Function<Integer, int[]> c -> new int[c];
Function<Interge, int[]> int[]::new;


0개의 댓글