source: java2python/core/src/test/java/testcode/Lambda.java

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 
1package testcode;
2
3import java.util.function.Function;
4
5import org.eclipse.jdt.annotation.NonNull;
6
7class 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 */
23public 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.