@@ -21,26 +21,28 @@ For more information, see the [Reflection Framework](https://github.com/mstrobel
21
21
22
22
#### Example
23
23
24
- :::java
25
- final Type<Map> map = Type.of(Map.class);
26
- final Type<?> rawMap = map.getErasedType();
27
- final Type<Map<String, Integer>> boundMap = map.makeGenericType(Types.String, Types.Integer);
28
-
29
- System.out.println(map.getDeclaredMethods().get(1));
30
- System.out.println(rawMap.getDeclaredMethods().get(1));
31
- System.out.println(boundMap.getDeclaredMethods().get(1));
32
-
33
- System.out.println(boundMap.getGenericTypeParameters());
34
- System.out.println(boundMap.getTypeArguments());
24
+ ``` java
25
+ final Type<Map > map = Type . of(Map . class);
26
+ final Type<?> rawMap = map. getErasedType();
27
+ final Type<Map<String , Integer > > boundMap = map. makeGenericType(Types . String , Types . Integer );
28
+
29
+ System . out. println(map. getDeclaredMethods(). get(1 ));
30
+ System . out. println(rawMap. getDeclaredMethods(). get(1 ));
31
+ System . out. println(boundMap. getDeclaredMethods(). get(1 ));
32
+
33
+ System . out. println(boundMap. getGenericTypeParameters());
34
+ System . out. println(boundMap. getTypeArguments());
35
+ ```
35
36
36
37
#### Output
37
38
38
- :::text
39
- public abstract V put(K, V)
40
- public abstract Object put(Object, Object)
41
- public abstract Integer put(String, Integer)
42
- [K, V]
43
- [java.lang.String, java.lang.Integer]
39
+ ``` text
40
+ public abstract V put(K, V)
41
+ public abstract Object put(Object, Object)
42
+ public abstract Integer put(String, Integer)
43
+ [K, V]
44
+ [java.lang.String, java.lang.Integer]
45
+ ```
44
46
45
47
### Expressions Framework
46
48
@@ -53,56 +55,58 @@ almost a direct port of `System.Linq.Expressions` from .NET's Dynamic Language R
53
55
minus the dynamic callsite support (and with more relaxed rules regarding type conversions).
54
56
55
57
#### Example
56
- :::java
57
- //
58
- // This lambda closes over a complex constant (a String array).
59
- //
60
-
61
- final ConstantExpression items = constant(
62
- new String[] { "one", "two", "three", "four", "five" }
63
- );
64
-
65
- //
66
- // If written in Java, the constructed expression would look something like this:
67
- //
68
- // () -> {
69
- // for (String item : <closure>items)
70
- // System.out.printf("Got item: %s\n", item);
71
- // }
72
- //
73
-
74
- final ParameterExpression item = variable(Types.String, "item");
75
-
76
- final LambdaExpression<Runnable> runnable = lambda(
77
- Type.of(Runnable.class),
78
- forEach(
79
- item,
80
- items,
81
- call(
82
- field(null, Types.System.getField("out")),
83
- "printf",
84
- constant("Got item: %s\n"),
85
- item
86
- )
58
+ ``` java
59
+ //
60
+ // This lambda closes over a complex constant (a String array).
61
+ //
62
+
63
+ final ConstantExpression items = constant(
64
+ new String [] { " one" , " two" , " three" , " four" , " five" }
65
+ );
66
+
67
+ //
68
+ // If written in Java, the constructed expression would look something like this:
69
+ //
70
+ // () -> {
71
+ // for (String item : <closure>items)
72
+ // System.out.printf("Got item: %s\n", item);
73
+ // }
74
+ //
75
+
76
+ final ParameterExpression item = variable(Types . String , " item" );
77
+
78
+ final LambdaExpression<Runnable > runnable = lambda(
79
+ Type . of(Runnable . class),
80
+ forEach(
81
+ item,
82
+ items,
83
+ call(
84
+ field(null , Types . System . getField(" out" )),
85
+ " printf" ,
86
+ constant(" Got item: %s\n " ),
87
+ item
87
88
)
88
- );
89
-
90
- System.out.println(runnable);
91
-
92
- final Runnable delegate = runnable.compile();
89
+ )
90
+ );
91
+
92
+ System . out. println(runnable);
93
+
94
+ final Runnable delegate = runnable. compile();
93
95
94
- delegate.run();
96
+ delegate. run();
97
+ ```
95
98
96
99
#### Output
97
- :::text
98
- () => for (String item : [one, two, three, four, five])
99
- System.out.printf("Got item: %s\n", new Object[] { item })
100
-
101
- Got item: one
102
- Got item: two
103
- Got item: three
104
- Got item: four
105
- Got item: five
100
+ ``` text
101
+ () => for (String item : [one, two, three, four, five])
102
+ System.out.printf("Got item: %s\n", new Object[] { item })
103
+
104
+ Got item: one
105
+ Got item: two
106
+ Got item: three
107
+ Got item: four
108
+ Got item: five
109
+ ```
106
110
107
111
### Compiler Toolset
108
112
0 commit comments