1 | package testcode;
|
---|
2 |
|
---|
3 | import java.util.ArrayList;
|
---|
4 | import java.util.List;
|
---|
5 |
|
---|
6 | import org.eclipse.jdt.annotation.NonNull;
|
---|
7 |
|
---|
8 | import tudelft.annotations.Defer;
|
---|
9 |
|
---|
10 | interface TheInterface<T> {
|
---|
11 | T get();
|
---|
12 | }
|
---|
13 |
|
---|
14 | class MyType<T> implements TheInterface<T> {
|
---|
15 | private final @NonNull T value;
|
---|
16 |
|
---|
17 | public MyType(@NonNull T val) {
|
---|
18 | this.value = val;
|
---|
19 | }
|
---|
20 |
|
---|
21 | @NonNull
|
---|
22 | public T get() {
|
---|
23 | return value;
|
---|
24 | }
|
---|
25 | }
|
---|
26 |
|
---|
27 | /**
|
---|
28 | * Test for translation to python.<br>
|
---|
29 | * Extra line for multiline-test.
|
---|
30 | */
|
---|
31 | public class Generics {
|
---|
32 |
|
---|
33 | /**
|
---|
34 | * Not called, only for testing this is translated to getString(self) ->
|
---|
35 | * "str"
|
---|
36 | */
|
---|
37 | public @NonNull @Defer String getString() {
|
---|
38 | return "1";
|
---|
39 | }
|
---|
40 |
|
---|
41 | private static @NonNull String test1() {
|
---|
42 | @NonNull
|
---|
43 | List<@NonNull MyType<@NonNull String>> myList = new ArrayList<>();
|
---|
44 | myList.add(new MyType("d"));
|
---|
45 | return myList.get(0).get();
|
---|
46 | }
|
---|
47 |
|
---|
48 | private static @NonNull MyType<@NonNull String> test2() {
|
---|
49 | return new MyType<String>("d");
|
---|
50 | }
|
---|
51 |
|
---|
52 | static public void main(String[] args) {
|
---|
53 | System.out.println(test1());
|
---|
54 | System.out.println(getValue(1).toString());
|
---|
55 | System.out.println(getValue(1d) == null ? "null" : "?");
|
---|
56 | System.out.println(test2().get());
|
---|
57 |
|
---|
58 | final @NonNull MyType<@NonNull @Defer String> deferred = new MyType<@Defer String>(
|
---|
59 | "deferred");
|
---|
60 | System.out.println(deferred.get());
|
---|
61 | }
|
---|
62 |
|
---|
63 | private static <U extends Number> U getValue(@NonNull U val) {
|
---|
64 | if (val instanceof Integer)
|
---|
65 | return (U) val;
|
---|
66 | return null;
|
---|
67 | }
|
---|
68 |
|
---|
69 | }
|
---|