Lambda
ν¨μν μΈν°νμ΄μ€(Functional Interface)
@FunctionalInterface
interface MyFunction {
int max(int a, int b);
// int min(int a, int b); // μ£Όμ ν΄μ μ μ»΄νμΌ μλ¬ λ°μ
}
class Main {
public static void main(String[] args) {
// 1. μ΅λͺ
ν΄λμ€ μ¬μ©
MyFunction f1 = new MyFunction() {
public int max(int a, int b) {
return a > b ? a : b;
}
};
// 2. λλ€μ μ¬μ© (μ΅λͺ
κ°μ²΄λ₯Ό λ체)
MyFunction f2 = (a, b) -> a > b ? a : b;
}
}μ΅λͺ
ν΄λμ€μμ μ°¨μ΄μ
java.util.function ν¨ν€μ§
μΈν°νμ΄μ€
λ©μλ
λ§€κ°λ³μ
λ°νκ°
μ€λͺ
λ©μλ μ°Έμ‘°(Method Reference)
μ’
λ₯
λλ€μ μμ
λ©μλ μ°Έμ‘°
Last updated