File: LambdaExpr19.java

package info (click to toggle)
libnb-javaparser-java 9%2B2018-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 65,320 kB
  • sloc: java: 440,096; xml: 6,359; sh: 865; makefile: 314
file content (53 lines) | stat: -rw-r--r-- 1,109 bytes parent folder | download | duplicates (19)
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
/*
 * @test /nodynamiccopyright/
 * @bug 8003280
 * @summary Add lambda tests
 *  check that inner scopes are left after a lambda check exception has been thrown
 * @compile/fail/ref=LambdaExpr19.out -XDrawDiagnostics LambdaExpr19.java
 */
class LambdaExpr19 {

    interface SAM {
        String m();
    }

    void m(SAM s) { }

    void testTry() {
        m(() -> {
                try { return 1; }
                catch (Exception e) { }
            });
    }

    void testTryWithResources() {
        m(() -> {
                try (AutoCloseable c = null) { return 1; }
                catch (Exception e) { }
            });
    }

    void testSwitch() {
        m(() -> {
                switch (1) {
                    default: return 1;
                }
            });
    }

    void testFor() {
        m(() -> {
                for (;;) {
                    return 1;
                }
            });
    }

    void testForeach() {
        m(() -> {
                for (Object o : new Object[] { null , null }) {
                    return 1;
                }
            });
    }
}