forked from eugenp/tutorials
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUseFoo.java
More file actions
38 lines (27 loc) · 973 Bytes
/
UseFoo.java
File metadata and controls
38 lines (27 loc) · 973 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
32
33
34
35
36
37
38
package com.baeldung;
import java.util.function.Function;
public class UseFoo {
private String value = "Enclosing scope value";
public String add(final String string, final Foo foo) {
return foo.method(string);
}
public String addWithStandardFI(final String string, final Function<String, String> fn) {
return fn.apply(string);
}
public String scopeExperiment() {
final Foo fooIC = new Foo() {
String value = "Inner class value";
@Override
public String method(final String string) {
return value;
}
};
final String resultIC = fooIC.method("");
final Foo fooLambda = parameter -> {
final String value = "Lambda value";
return this.value;
};
final String resultLambda = fooLambda.method("");
return "Results: resultIC = " + resultIC + ", resultLambda = " + resultLambda;
}
}