추상메소드
R apply(T t)
Function<파라미터타입,리턴타입>
클래스 타입이 오는 거라서 int는 올 수 없음 Integer써줘야함
문법
Function<Integer, Double> fun = new Function<Integer, Double>() {
@Override
public Double apply(Integer t) {
return t/2.0;
}
};
double a = fun.apply(5);
System.out.println("a: "+a);
Function<Integer, Double> fun=t->t/2.0;
//첫줄 = 파라미터->return문;
double a = fun.apply(5);
System.out.println("a: "+a);
Student객체를 파라미터로 전달받아 학점을 리턴하는 Function인터페이스를 람다식으로 이용해 만들고 사용해 보세요 . 학점: 90점 이상 "A" 등
사용될 Student메소드 : getScore()
생성자 Student(int num,String name,int score){}
Function<Student,Integer> fun=t->t.getScore()/10;
int n=fun.apply(new Student(1,"한소라",99));
switch(n){
case 10:
case 9: System.out.println("A"); break;
case 8: System.out.println("B"); break;
case 7: System.out.println("C"); break;
case 6: System.out.println("D"); break;
case 5:
case 4:
case 3:
case 2:
case 1:
case 0: System.out.println("F"); break;
}