cource2 - part.2 - ch03
단, 하나의 추상 메서드를 가진 인터페이스를 의미한다.
함수형 인터페이스는 @ FunctionalInterface어노테이션을 사용하여 표시 할 수 있다.
이 어노테이션은 선택 사항이지만, 컴파일러에게 해당 인터페이스가 함수형 인터페이스임을 알려주는 역할이다.
public class FunctionInterfaceTest implements MathOperation
{
public static void main(String[] args) {
MathOperation mo = new FunctionInterfaceTest();
int result = mo.operation(10, 20);
System.out.println("result = " + result); // 30
}
@Override
public int operation(int x, int y) {
return x+y;
}
}
public static void main(String[] args) {
// MathOperation 인터페이스를 내부에 [익명 내부 클래스]로 구현해보자.
// 인터페이스는 반드시 구현체가 필요하다. 그리고 객체로 생성 할 수 없다.
MathOperation mo = new MathOperation() {
@Override
public int operation(int x, int y) {
return 0;
}
};
int result = mo.operation(10, 20);
System.out.println("result = " + result);
}