-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJavaLambdas.java
More file actions
50 lines (39 loc) · 1.27 KB
/
JavaLambdas.java
File metadata and controls
50 lines (39 loc) · 1.27 KB
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package com.lambda.java;
public class JavaLambdas {
/*
* OOPS Java public String addString() { return "Hello World"; }
*/
// Functional
private String addString(LambdaInterface lambdaInterface) {
return lambdaInterface.greet();
}
public static void main(String[] args) {
JavaLambdas javaLambdas = new JavaLambdas();
LambdaImplementation lambdaImplementation = new LambdaImplementation();
System.out.println(lambdaImplementation.greet());
MyLambda mylambdaExpression = () -> "Hello World from lambda";
System.out.println(mylambdaExpression.addString());
MyLambdaVoid myLambdaVoid = () -> System.out.println("Hello World from labda Void");
myLambdaVoid.addString();
MyLambdaAddDoubles lambdaAddDoubles = (Double x, Double y) -> x + y;
System.out.println("My lambda Double Adds " + lambdaAddDoubles.addDoubles(2.2, 33.3));
// Anonymous class
LambdaInterface lambdaInterface = new LambdaInterface() {
@Override
public String greet() {
// TODO Auto-generated method stub
return "Hello World from Anonymous class";
}
};
System.out.println(lambdaInterface.greet());
}
interface MyLambda {
String addString();
}
interface MyLambdaVoid {
void addString();
}
interface MyLambdaAddDoubles {
Double addDoubles(Double x, Double y);
}
}