JAVA에서는 메서드로 소통하지 못하는데 인터페이스를 이용하여 메서드를 전달하기 위해서는 람다를 사용해야 한다.
package ex07.ch02;
interface Can1 { // 인터페이스로 정의
void run();
}
public class Beh01 {
static void start(Can1 can1) { //
can1.run();
}
public static void main(String[] args) {
start(() -> {
System.out.println("달리자1");
});
start(() -> {
System.out.println("달리자2");
});
}
}
Share article