인프런 워밍업 클럽 스터디 0기
BE 3일차
class Animal{
public String bark(){
return "동물이 웁니다";
}
}
public class Main{
public static void main(String[] args){
Animal dog = new Animal(){
@Override
public String bark(){
return "개가 짖습니다";
}
};
dog.bark();
}
}
- 기본 문법
(타입 매개변수) -> {실행문}
- 예시
(int a) -> {System.out.println(a);}
a -> System.out.println(a);
(x,y) -> x+y;
람다식은 인터페이스 변수다?
@FunctionalInterface
public interface MyFunctionalInterface{
public int sum(int x,int y);
}
//Main
MyFunctionalInterface mi = (x,y) -> x+y;
System.out.println(mi.sum(3,6));
함수형 인터페이스 | Descripter | Method |
---|---|---|
Predicate | T->boolean | boolean test(T t) |
Consumer | T->void | void accept(T t) |
Supplier | ()->T | T get() |
Function<T, R> | T->R | R apply(T t) |
Comparator | (T,T)->int | int compare(T o1, T o2) |
Runnable | ()->void | void run() |
Callable | ()->T | T call() |
Map<String,Integer>map = new HashMap<>();
map.entrySet().stream()
.filter(e->e.getKey().contains("it"))
.filter(e->e.getValue()>150)
.forEach(e->System.out.println(e.getKey()+e.getValue()));
Stream stream = Stream.iterate(2,n->n+2);
stream.forEach(System.out::println);
https://steady-coding.tistory.com/304
https://www.codelatte.io/courses/java_programming_basic/O2PZAC2T82LKBXAY
https://bcp0109.tistory.com/313