@@ -11,7 +11,8 @@ class A {
11
11
A a = new A ();
12
12
B b = new B ();
13
13
14
- public Integer captureNone (Float x , Integer y , BiFunction <Float , Integer , Integer > fun ) {
14
+ public Integer captureNone (Float x , Integer y ,
15
+ BiFunction <Float , Integer , Integer > fun ) {
15
16
return fun .apply (x , y );
16
17
}
17
18
@@ -62,111 +63,103 @@ public int captureAndAssign(int x) {
62
63
}
63
64
64
65
// test static field of different class
65
- public double callStatic (Double x ) {
66
- return B .dmul .apply (x );
67
- }
66
+ public double callStatic (Double x ) { return B .dmul .apply (x ); }
68
67
69
- public int capture2 (Float a ) {
70
- return add .apply (a , 1 );
71
- }
68
+ public int capture2 (Float a ) { return add .apply (a , 1 ); }
72
69
73
- public boolean custom (Integer i ) {
74
- return custom .is_ok (i );
75
- }
70
+ public boolean custom (Integer i ) { return custom .is_ok (i ); }
76
71
77
72
public static void main (String [] args , int unknown ) {
78
73
Lambdatest lt = new Lambdatest ();
79
- if (unknown == 0 )
80
- assert lt .captureNone (1.0f , 2 , (x , y ) -> x .intValue () + y ) == 3 ; // should succeed
81
- else if (unknown == 1 )
82
- assert lt .captureNone (1.0f , 2 , (x , y ) -> x .intValue () + y ) == 4 ; // should fail
83
- else if (unknown == 2 )
74
+ if (unknown == 0 ) {
75
+ // should succeed
76
+ assert lt .captureNone (1.0f , 2 , (x , y ) -> x .intValue () + y ) == 3 ;
77
+ } else if (unknown == 1 ) {
78
+ // should fail
79
+ assert lt .captureNone (1.0f , 2 , (x , y ) -> x .intValue () + y ) == 4 ;
80
+ } else if (unknown == 2 ) {
84
81
assert lt .captureReference (1.0f , 2 , 3 ) == 9 ; // should succeed
85
- else if (unknown == 3 )
82
+ } else if (unknown == 3 ) {
86
83
assert lt .captureReference (1.0f , 2 , 3 ) == 10 ; // should fail
87
- else if (unknown == 4 )
84
+ } else if (unknown == 4 ) {
88
85
assert lt .captureInt (2 ) == 10 ; // should succeed
89
- else if (unknown == 5 )
86
+ } else if (unknown == 5 ) {
90
87
assert lt .captureInt (2 ) == 11 ; // should fail
91
- else if (unknown == 6 )
88
+ } else if (unknown == 6 ) {
92
89
assert lt .captureThisPrimitive (3 ) == 30 ; // should succeed
93
- else if (unknown == 7 )
90
+ } else if (unknown == 7 ) {
94
91
assert lt .captureThisPrimitive (3 ) == 31 ; // should fail
95
- else if (unknown == 8 )
92
+ } else if (unknown == 8 ) {
96
93
assert lt .captureThisReference (4 ) == 40 ; // should succeed
97
- else if (unknown == 9 )
94
+ } else if (unknown == 9 ) {
98
95
assert lt .captureThisReference (4 ) == 41 ; // should fail
99
- else if (unknown == 10 )
100
- {
96
+ } else if (unknown == 10 ) {
101
97
assert lt .captureAndCall (5 ) == 70 ; // should succeed
102
- assert lt .b .y == 70 ; // check side-effects of l method
103
- }
104
- else if (unknown == 11 )
98
+ assert lt .b .y == 70 ; // check side-effects of l method
99
+ } else if (unknown == 11 ) {
105
100
assert lt .captureAndCall (5 ) == 51 ; // should fail
106
- else if (unknown == 12 )
107
- {
101
+ } else if (unknown == 12 ) {
108
102
assert lt .captureAndAssign (6 ) == 60 ; // should succeed
109
- assert lt .b .y == 60 ; // check side-effects of m method
110
- }
111
- else if (unknown == 13 )
103
+ assert lt .b .y == 60 ; // check side-effects of m method
104
+ } else if (unknown == 13 ) {
112
105
assert lt .captureAndAssign (6 ) == 61 ; // should fail
113
- else if (unknown == 14 )
106
+ } else if (unknown == 14 ) {
114
107
assert lt .callStatic (7.0 ) == 10.5 ; // should succeed
115
- else if (unknown == 15 )
108
+ } else if (unknown == 15 ) {
116
109
assert lt .callStatic (7.0 ) == 12 ; // should fail
117
- else if (unknown == 16 )
110
+ } else if (unknown == 16 ) {
118
111
assert lt .capture2 (8.0f ) == 9 ; // should succeed
119
- else if (unknown == 17 )
112
+ } else if (unknown == 17 ) {
120
113
assert lt .capture2 (8.0f ) == 10 ; // should fail
121
- else if (unknown == 18 )
114
+ } else if (unknown == 18 ) {
122
115
assert lt .custom (9 ); // should succeed
123
- else if (unknown == 19 )
116
+ } else if (unknown == 19 ) {
124
117
assert !lt .custom (9 ); // should fail
125
- // Test array capture
126
- else if (unknown == 20 ) {
118
+ // Test array capture
119
+ } else if (unknown == 20 ) {
127
120
int array [] = new int [3 ];
128
121
Function <Integer , Integer > func = (x ) -> x + array .length ;
129
122
assert func .apply (2 ) == 5 ; // should succeed
130
- } else if (unknown == 21 ) {
123
+ } else if (unknown == 21 ) {
131
124
int array [] = new int [3 ];
132
125
Function <Integer , Integer > func = (x ) -> x + array .length ;
133
126
assert func .apply (2 ) == 6 ; // should fail
134
- // Test reference array
135
- } else if (unknown == 22 ) {
127
+ // Test reference array
128
+ } else if (unknown == 22 ) {
136
129
Integer array [] = new Integer [3 ];
137
130
Function <Integer , Integer > func = (x ) -> x + array .length ;
138
131
assert func .apply (2 ) == 5 ; // should succeed
139
- } else if (unknown == 23 ) {
132
+ } else if (unknown == 23 ) {
140
133
Integer array [] = new Integer [3 ];
141
134
Function <Integer , Integer > func = (x ) -> x + array .length ;
142
135
assert func .apply (2 ) == 6 ; // should fail
143
- // Test outer class capture
144
- } else if (unknown == 24 ) {
136
+ // Test outer class capture
137
+ } else if (unknown == 24 ) {
145
138
Outer outer = new Outer ();
146
139
outer .value = 42 ;
147
140
Outer .Inner inner = outer .new Inner ();
148
141
Function <Integer , Integer > getter = inner .getOuterGetter ();
149
- assert (getter .apply (0 ) == 42 ); // should succeed
150
- } else if (unknown == 25 ) {
142
+ assert (getter .apply (0 ) == 42 ); // should succeed
143
+ } else if (unknown == 25 ) {
151
144
Outer outer = new Outer ();
152
145
outer .value = 42 ;
153
146
Outer .Inner inner = outer .new Inner ();
154
147
Function <Integer , Integer > getter = inner .getOuterGetter ();
155
- assert (getter .apply (0 ) != 42 ); // should fail
156
- // Static intialized lambda
157
- } else if (unknown == 26 ) {
148
+ assert (getter .apply (0 ) != 42 ); // should fail
149
+ // Static intialized lambda
150
+ } else if (unknown == 26 ) {
158
151
assert StaticLambdas .id .apply (96 ) == 96 ; // should succeed
159
- } else if (unknown == 27 ) {
152
+ } else if (unknown == 27 ) {
160
153
assert StaticLambdas .id .apply (96 ) != 96 ; // should fail
161
- // Reference equality of the captured object
162
- } else if (unknown == 28 ) {
154
+ // Reference equality of the captured object
155
+ } else if (unknown == 28 ) {
163
156
Object object = new Object ();
164
157
Function <Integer , Object > lambda = (x ) -> object ;
165
- assert (lambda .apply (0 ) == object ); // should succeed
166
- } else if (unknown == 29 ) {
158
+ assert (lambda .apply (0 ) == object ); // should succeed
159
+ } else if (unknown == 29 ) {
167
160
Object object = new Object ();
168
161
Function <Integer , Object > lambda = (x ) -> object ;
169
- assert (lambda .apply (0 ) != object ); // should fail
162
+ assert (lambda .apply (0 ) != object ); // should fail
170
163
}
171
164
}
172
165
@@ -183,14 +176,10 @@ class StaticLambdas {
183
176
class Outer {
184
177
int value ;
185
178
class Inner {
186
- Function <Integer , Integer > getOuterGetter () {
187
- return (x ) -> value ;
188
- }
179
+ Function <Integer , Integer > getOuterGetter () { return (x ) -> value ; }
189
180
}
190
181
}
191
182
192
183
class C implements CustomLambda <Integer > {
193
- public boolean is_ok (Integer i ) {
194
- return true ;
195
- }
184
+ public boolean is_ok (Integer i ) { return true ; }
196
185
}
0 commit comments