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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
|
// VIM_TEST_SETUP let g:java_highlight_functions = 'style'
import java.lang.annotation.ElementType;
import java.util.function.BinaryOperator;
import java.util.function.Function;
import java.util.function.Predicate;
class LambdaExpressionsTests // JDK 21+.
{
<I1, C1, C2, T1, T2, T3, Z1, Z2, Z3, S1, S2, S3> void test()
{ // Schönfinkel's functions.
I<I1> i = x -> x;
C<C1, C2> c = x -> y -> x;
T<T1, T2, T3> t = f -> y -> x -> f.apply(x).apply(y);
Z<Z1, Z2, Z3> z = f -> g -> x -> f.apply(g.apply(x));
S<S1, S2, S3> s = f -> g -> x -> f.apply(x)
.apply(g.apply(x));
I<I1> i01 = (var x) -> x;
I<I1> i02 = (@Taggable var x) -> x;
I<I1> i03 = (@Taggable @Taggable var x) -> x;
I<I1> i04 = (final var x) -> x;
I<I1> i05 = (@Taggable final var x) -> x;
I<I1> i06 = (@Taggable @Taggable final var x) -> x;
I<I1> i07 = (I1 x) -> x;
I<I1> i08 = (@Taggable I1 x) -> x;
I<I1> i09 = (@Taggable @Taggable I1 x) -> x;
I<I1> i10 = (final I1 x) -> x;
I<I1> i11 = (@Taggable final I1 x) -> x;
I<I1> i12 = (@Taggable @Taggable final I1 x) -> x;
I<I1[]> ii01 = (I1... x) -> x;
I<I1[]> ii02 = (@Taggable I1... x) -> x;
I<I1[]> ii03 = (@Taggable @Taggable I1... x) -> x;
I<I1[]> ii04 = (final I1... x) -> x;
I<I1[]> ii05 = (@Taggable final I1... x) -> x;
I<I1[]> ii06 = (@Taggable @Taggable final I1... x) -> x;
BinaryOperator<I1> leftConst01 = (var x, var y) -> x;
BinaryOperator<I1> leftConst02 = (@Taggable var x,
@Taggable var y) -> x;
BinaryOperator<I1> leftConst03 = (@Taggable @Taggable var
x, @Taggable @Taggable var y) -> x;
BinaryOperator<I1> leftConst04 = (final var x,
final var y) -> x;
BinaryOperator<I1> leftConst05 = (@Taggable final
var x, @Taggable final var y) -> x;
BinaryOperator<I1> leftConst06 = (@Taggable
@Taggable final var x,
@Taggable
@Taggable final var y) -> x;
BinaryOperator<I1> leftConst07 = (I1 x, I1 y) -> x;
BinaryOperator<I1> leftConst08 = (@Taggable I1 x,
@Taggable I1 y) -> x;
BinaryOperator<I1> leftConst09 = (@Taggable @Taggable I1
x, @Taggable @Taggable I1 y) -> x;
BinaryOperator<I1> leftConst10 = (final I1 x,
final I1 y) -> x;
BinaryOperator<I1> leftConst11 = (@Taggable final
I1 x, @Taggable final I1 y) -> x;
BinaryOperator<I1> leftConst12 = (@Taggable
@Taggable final I1 x,
@Taggable
@Taggable final I1 y) -> x;
Runnable noOp = () -> {};
BinaryOperator<I1> leftConst = (x, y) -> x;
I<I1> id1 = (x) -> (x);
@SuppressWarnings("unchecked") I<I1> id2 =
((I<I<I1>>) (I<?>) (Function<I1,
I1> x) -> x).apply(switch (0) {
case ((int) (byte) 1) -> (I1 x) -> x;
default -> (@Taggable I1 x) -> x; });
C<C1, C2> const1 = (x) -> (y) -> (x);
C<C1, C2> const2 = switch(switch ("") {
case "->"->"(s)->(s)";
default->"default"; }) {
case ("->")->(var x)->(var y)->(x);
default->(@Taggable var x)->(@Taggable var y)
->(x);
};
}
@java.lang.annotation.Target(ElementType.PARAMETER)
@java.lang.annotation.Repeatable(Taggables.class)
@interface Taggable { String[] value() default ""; }
@java.lang.annotation.Target(ElementType.PARAMETER)
@interface Taggables { Taggable[] value(); }
interface I<A1> extends Function<A1, A1> { }
interface C<A1, A2> extends Function<A1, Function<A2, A1>> { }
interface T<A1, A2, A3> extends
Function<Function<A1, Function<A2, A3>>,
Function<A2,
Function<A1, A3>>> { }
interface Z<A1, A2, A3> extends Function<Function<A2, A3>,
Function<Function<A1, A2>,
Function<A1, A3>>> { }
interface S<A1, A2, A3> extends
Function<Function<A1, Function<A2, A3>>,
Function<Function<A1, A2>,
Function<A1, A3>>> { }
static void echo(Object o) { System.out.println(o); }
static {
enum Letters { OTHER, ALPHA, BETA }
Letters other = Letters.OTHER;
switch (other) {
case Letters alpha when Letters.ALPHA == alpha:
{ echo(alpha); break; }
case Letters beta when Letters.BETA == beta:
{ echo(beta); break; }
default: { echo(other); }
}
echo(switch (other) {
case Letters alpha when Letters.ALPHA == alpha
-> alpha;
case Letters beta when Letters.BETA == beta
-> beta;
default -> other;
});
switch (null) {
case String str when !"<empty>".equals(switch (str) {
case String str_ when
Predicate.<String>not(text ->
!text.isEmpty())
.test(str_)
-> "<empty>";
case String str_ -> str_;
}): { echo(str); break; }
case null: default: { echo("Other"); }
}
echo(switch (null) {
case String str when !"<empty>".equals(
switch (str) {
case String str_ when
Predicate.<String>not(text ->
!text.isEmpty())
.test(str_)
-> "<empty>";
case String str_ -> str_;
}) -> str;
case null, default -> "Other";
});
}
}
|