프로그래밍 명령형(절차형) 과 선언형(함수형) 기법이 있다. 함수를 만들고 그것을 호출하는 것까지 한 줄 코드로 작성하는 것을 람다식이라고 한다.
.....
Greet b = new Greet(){
public String greet(String name) {
return("Hello"+name);
}
.......
==>Greet b = (String name) -> {return "Hello" +name};
package java13;
@FunctionalInterface //Annotation이라고 하는데 일종의 주석문 처럼 실행되지는 않지만 Spring등에서
//메써드를 빠르게 찾아주는 등의 역할을 한다. 처리속도를 빠르게 사용된다.
interface CalcPower{ // 무명 클래스
public Integer calc(Integer n); // 무명 메써드
}
public class Test10 {
public static void main(String[] args) {
// TODO Auto-generated method stub
CalcPower pownum = n ->{return n * n;}; // 람다 식
System.out.println(pownum.calc(11));
}
}

'JAVA' 카테고리의 다른 글
| [JAVA] 제네릭(Generic) (0) | 2022.08.03 |
|---|---|
| [JAVA]다형성 (0) | 2022.08.03 |
| [JAVA]collections, set/list/map인터페이스 (0) | 2022.08.03 |
| [JAVA] ArrayList (0) | 2022.08.03 |
| [JAVA] MAP (0) | 2022.08.03 |
댓글