-
Notifications
You must be signed in to change notification settings - Fork 27
Expand file tree
/
Copy pathJavaLambdaEx.java
More file actions
31 lines (23 loc) · 781 Bytes
/
JavaLambdaEx.java
File metadata and controls
31 lines (23 loc) · 781 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
package com.zetcode;
@FunctionalInterface
interface MathOperation {
int mdo(int a, int b);
}
public class JavaLambdaEx {
public static void main(String[] args) {
// with type declaration
MathOperation add = (int a, int b) -> a + b;
// without type declaration
MathOperation sub = (a, b) -> a - b;
// with return statement along with curly braces
MathOperation mul = (int a, int b) -> {
return a * b;
};
// without return statement and without curly braces
MathOperation div = (int a, int b) -> a / b;
System.out.println(add.mdo(4, 5));
System.out.println(sub.mdo(6, 5));
System.out.println(mul.mdo(4, 5));
System.out.println(div.mdo(4, 2));
}
}