package ex07.ch02;
/*
1.Consumer
2.Supplier
3.Predicate //(true or talse) 논리
4.Function
5.Callable
*/
//소비하는 친구
interface Con01 {
void accept(int n);
}
//공급하는 친구
interface Sup01 {
int get();
}
//예견하는 친구
interface Pre01 {
boolean test(int n);
}
//함수
interface Fun01 {
int apply(int n1, int n2);
}
interface Cal01 {
void call();
}
// 절대 만들지마라!! 써먹기만 하면 된다.
public class Beh02 {
public static void main(String[] args) {
//1.Consumer
Con01 c1 = (n) -> {//함수를 담고있는 식
System.out.println("소비" + n);
};
c1.accept(10);
//2.Supplier
Sup01 s1 = () -> 1; //중괄호 안쓰면 자동으로 return코드가 사용
int r1 = s1.get();
System.out.println("공급받음" + r1);
//3.Predicate
Pre01 p1 = (n) -> n % 2 == 0;
Pre01 p2 = (n) -> n % 2 == 0;
System.out.println("에측함:" + p1.test(5));
System.out.println("에측함:" + p2.test(6));
//4.Function
Fun01 add = (n1, n2) -> n1 + n2;
Fun01 sub = (n1, n2) -> n1 - n2;
Fun01 mul = (n1, n2) -> n1 * n2;
Fun01 div = (n1, n2) -> n1 / n2;
System.out.println("함수:" + add.apply(1, 2));
System.out.println("함수:" + add.apply(4, 5));
//5.Callable
Cal01 ca1 = () -> {
System.out.println("기본함수");
};
ca1.call();
}
}
Share article