Thu, 10 Oct 2013 14:58:04 +0200
8001931: The new build system whitespace cleanup
Reviewed-by: tbell, simonis, erikj
1 /*
2 * @test /nodynamiccopyright/
3 * @bug 8003280
4 * @summary Add lambda tests
5 * Integrate efectively final check with DA/DU analysis
6 * @compile/fail/ref=LambdaEffectivelyFinalTest.out -XDrawDiagnostics LambdaEffectivelyFinalTest.java
7 */
8 class LambdaEffectivelyFinalTest {
10 interface SAM {
11 int m();
12 }
14 void foo(LambdaEffectivelyFinalTest.SAM s) { }
16 void m1(int x) {
17 int y = 1;
18 foo(() -> x+y); // Legal: x and y are both effectively final.
19 }
21 void m2(int x) {
22 int y;
23 y = 1;
24 foo(() -> x+y); // Legal: x and y are both effectively final.
25 }
27 void m3(int x, boolean cond) {
28 int y;
29 if (cond) y = 1;
30 foo(() -> x+y); // Illegal: y is effectively final, but not definitely assigned.
31 }
33 void m4(int x, boolean cond) {
34 int y;
35 if (cond) y = 1;
36 else y = 2;
37 foo(() -> x+y); // Legal: x and y are both effectively final.
38 }
40 void m5(int x, boolean cond) {
41 int y;
42 if (cond) y = 1;
43 y = 2;
44 foo(() -> x+y); // Illegal: y is not effectively final.t EF
45 }
47 void m6(int x) {
48 foo(() -> x+1);
49 x++; // Illegal: x is not effectively final.
50 }
52 void m7(int x) {
53 foo(() -> x=1); // Illegal: x in the assignment does not denote a variable (see 6.5.6.1)
54 }
56 void m8() {
57 int y;
58 foo(() -> y=1); // Illegal: y in the assignment does not denote a variable (see 6.5.6.1)
59 }
60 }