Last change
on this file was 800, checked in by wouter, 6 months ago |
converted javax.annotation to org.eclipse.jdt.annotation because javax is deprecated and no maven substitute available.
|
File size:
898 bytes
|
Line | |
---|
1 | package testcode;
|
---|
2 |
|
---|
3 | import java.util.function.Function;
|
---|
4 |
|
---|
5 | import org.eclipse.jdt.annotation.NonNull;
|
---|
6 |
|
---|
7 | class A {
|
---|
8 | private final @NonNull Function<Integer, Integer> g;
|
---|
9 |
|
---|
10 | public A(final @NonNull Function<Integer, Integer> g) {
|
---|
11 | this.g = g;
|
---|
12 | }
|
---|
13 |
|
---|
14 | public int f(int x) {
|
---|
15 | return g.apply(x);
|
---|
16 | }
|
---|
17 | }
|
---|
18 |
|
---|
19 | /**
|
---|
20 | * Test for translation to python.<br>
|
---|
21 | * Extra line for multiline-test.
|
---|
22 | */
|
---|
23 | public class Lambda {
|
---|
24 |
|
---|
25 | public Lambda() {
|
---|
26 | System.out.println(test1() + "1");
|
---|
27 | System.out.println(test2() + "2");
|
---|
28 | }
|
---|
29 |
|
---|
30 | private @NonNull String test1() {
|
---|
31 | final @NonNull Function<Integer, Integer> g = x -> x + 1;
|
---|
32 | return g.apply(1) == 2 ? "ok" : "ko";
|
---|
33 | }
|
---|
34 |
|
---|
35 | private @NonNull String test2() {
|
---|
36 | final @NonNull A a = new A((Function<Integer, Integer>) x -> x * x);
|
---|
37 | return a.f(2) == 4 ? "ok" : "ko";
|
---|
38 | }
|
---|
39 |
|
---|
40 | /**
|
---|
41 | *
|
---|
42 | * @param args the arguments of the call.
|
---|
43 | */
|
---|
44 | static public void main(String[] args) {
|
---|
45 | new Lambda();
|
---|
46 | }
|
---|
47 |
|
---|
48 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.