author | jlahoda |
Wed, 09 Dec 2015 14:26:56 +0100 | |
changeset 34565 | 627464b87753 |
permissions | -rw-r--r-- |
34565
627464b87753
8080641: JEP-JDK-8042880 : Implement new tests on Project Coin
jlahoda
parents:
diff
changeset
|
1 |
/* |
627464b87753
8080641: JEP-JDK-8042880 : Implement new tests on Project Coin
jlahoda
parents:
diff
changeset
|
2 |
* @test /nodynamiccopyright/ |
627464b87753
8080641: JEP-JDK-8042880 : Implement new tests on Project Coin
jlahoda
parents:
diff
changeset
|
3 |
* @bug 7196163 |
627464b87753
8080641: JEP-JDK-8042880 : Implement new tests on Project Coin
jlahoda
parents:
diff
changeset
|
4 |
* @summary Twr with resource variables as lambda expressions and method references |
627464b87753
8080641: JEP-JDK-8042880 : Implement new tests on Project Coin
jlahoda
parents:
diff
changeset
|
5 |
* @compile/fail/ref=TwrAndLambda.out -XDrawDiagnostics TwrAndLambda.java |
627464b87753
8080641: JEP-JDK-8042880 : Implement new tests on Project Coin
jlahoda
parents:
diff
changeset
|
6 |
*/ |
627464b87753
8080641: JEP-JDK-8042880 : Implement new tests on Project Coin
jlahoda
parents:
diff
changeset
|
7 |
|
627464b87753
8080641: JEP-JDK-8042880 : Implement new tests on Project Coin
jlahoda
parents:
diff
changeset
|
8 |
public class TwrAndLambda { |
627464b87753
8080641: JEP-JDK-8042880 : Implement new tests on Project Coin
jlahoda
parents:
diff
changeset
|
9 |
|
627464b87753
8080641: JEP-JDK-8042880 : Implement new tests on Project Coin
jlahoda
parents:
diff
changeset
|
10 |
public static void main(String... args) { |
627464b87753
8080641: JEP-JDK-8042880 : Implement new tests on Project Coin
jlahoda
parents:
diff
changeset
|
11 |
|
627464b87753
8080641: JEP-JDK-8042880 : Implement new tests on Project Coin
jlahoda
parents:
diff
changeset
|
12 |
// Lambda expression |
627464b87753
8080641: JEP-JDK-8042880 : Implement new tests on Project Coin
jlahoda
parents:
diff
changeset
|
13 |
AutoCloseable v1 = () -> {}; |
627464b87753
8080641: JEP-JDK-8042880 : Implement new tests on Project Coin
jlahoda
parents:
diff
changeset
|
14 |
// Static method reference |
627464b87753
8080641: JEP-JDK-8042880 : Implement new tests on Project Coin
jlahoda
parents:
diff
changeset
|
15 |
AutoCloseable v2 = TwrAndLambda::close1; |
627464b87753
8080641: JEP-JDK-8042880 : Implement new tests on Project Coin
jlahoda
parents:
diff
changeset
|
16 |
// Instance method reference |
627464b87753
8080641: JEP-JDK-8042880 : Implement new tests on Project Coin
jlahoda
parents:
diff
changeset
|
17 |
AutoCloseable v3 = new TwrAndLambda()::close2; |
627464b87753
8080641: JEP-JDK-8042880 : Implement new tests on Project Coin
jlahoda
parents:
diff
changeset
|
18 |
// Lambda expression which is not AutoCloseable |
627464b87753
8080641: JEP-JDK-8042880 : Implement new tests on Project Coin
jlahoda
parents:
diff
changeset
|
19 |
Runnable r1 = () -> {}; |
627464b87753
8080641: JEP-JDK-8042880 : Implement new tests on Project Coin
jlahoda
parents:
diff
changeset
|
20 |
// Static method reference which is not AutoCloseable |
627464b87753
8080641: JEP-JDK-8042880 : Implement new tests on Project Coin
jlahoda
parents:
diff
changeset
|
21 |
Runnable r2 = TwrAndLambda::close1; |
627464b87753
8080641: JEP-JDK-8042880 : Implement new tests on Project Coin
jlahoda
parents:
diff
changeset
|
22 |
// Instance method reference which is not AutoCloseable |
627464b87753
8080641: JEP-JDK-8042880 : Implement new tests on Project Coin
jlahoda
parents:
diff
changeset
|
23 |
Runnable r3 = new TwrAndLambda()::close2; |
627464b87753
8080641: JEP-JDK-8042880 : Implement new tests on Project Coin
jlahoda
parents:
diff
changeset
|
24 |
|
627464b87753
8080641: JEP-JDK-8042880 : Implement new tests on Project Coin
jlahoda
parents:
diff
changeset
|
25 |
try (v1) { |
627464b87753
8080641: JEP-JDK-8042880 : Implement new tests on Project Coin
jlahoda
parents:
diff
changeset
|
26 |
} catch(Exception e) {} |
627464b87753
8080641: JEP-JDK-8042880 : Implement new tests on Project Coin
jlahoda
parents:
diff
changeset
|
27 |
try (v2) { |
627464b87753
8080641: JEP-JDK-8042880 : Implement new tests on Project Coin
jlahoda
parents:
diff
changeset
|
28 |
} catch(Exception e) {} |
627464b87753
8080641: JEP-JDK-8042880 : Implement new tests on Project Coin
jlahoda
parents:
diff
changeset
|
29 |
try (v3) { |
627464b87753
8080641: JEP-JDK-8042880 : Implement new tests on Project Coin
jlahoda
parents:
diff
changeset
|
30 |
} catch(Exception e) {} |
627464b87753
8080641: JEP-JDK-8042880 : Implement new tests on Project Coin
jlahoda
parents:
diff
changeset
|
31 |
try (r1) { |
627464b87753
8080641: JEP-JDK-8042880 : Implement new tests on Project Coin
jlahoda
parents:
diff
changeset
|
32 |
} catch(Exception e) {} |
627464b87753
8080641: JEP-JDK-8042880 : Implement new tests on Project Coin
jlahoda
parents:
diff
changeset
|
33 |
try (r2) { |
627464b87753
8080641: JEP-JDK-8042880 : Implement new tests on Project Coin
jlahoda
parents:
diff
changeset
|
34 |
} catch(Exception e) {} |
627464b87753
8080641: JEP-JDK-8042880 : Implement new tests on Project Coin
jlahoda
parents:
diff
changeset
|
35 |
try (r3) { |
627464b87753
8080641: JEP-JDK-8042880 : Implement new tests on Project Coin
jlahoda
parents:
diff
changeset
|
36 |
} catch(Exception e) {} |
627464b87753
8080641: JEP-JDK-8042880 : Implement new tests on Project Coin
jlahoda
parents:
diff
changeset
|
37 |
|
627464b87753
8080641: JEP-JDK-8042880 : Implement new tests on Project Coin
jlahoda
parents:
diff
changeset
|
38 |
// lambda invocation |
627464b87753
8080641: JEP-JDK-8042880 : Implement new tests on Project Coin
jlahoda
parents:
diff
changeset
|
39 |
I i = (x) -> { try(x) { } catch (Exception e) { } }; |
627464b87753
8080641: JEP-JDK-8042880 : Implement new tests on Project Coin
jlahoda
parents:
diff
changeset
|
40 |
i.m(v1); |
627464b87753
8080641: JEP-JDK-8042880 : Implement new tests on Project Coin
jlahoda
parents:
diff
changeset
|
41 |
i.m(v2); |
627464b87753
8080641: JEP-JDK-8042880 : Implement new tests on Project Coin
jlahoda
parents:
diff
changeset
|
42 |
i.m(v3); |
627464b87753
8080641: JEP-JDK-8042880 : Implement new tests on Project Coin
jlahoda
parents:
diff
changeset
|
43 |
i.m(r1); |
627464b87753
8080641: JEP-JDK-8042880 : Implement new tests on Project Coin
jlahoda
parents:
diff
changeset
|
44 |
i.m(r2); |
627464b87753
8080641: JEP-JDK-8042880 : Implement new tests on Project Coin
jlahoda
parents:
diff
changeset
|
45 |
i.m(r3); |
627464b87753
8080641: JEP-JDK-8042880 : Implement new tests on Project Coin
jlahoda
parents:
diff
changeset
|
46 |
} |
627464b87753
8080641: JEP-JDK-8042880 : Implement new tests on Project Coin
jlahoda
parents:
diff
changeset
|
47 |
|
627464b87753
8080641: JEP-JDK-8042880 : Implement new tests on Project Coin
jlahoda
parents:
diff
changeset
|
48 |
static interface I { |
627464b87753
8080641: JEP-JDK-8042880 : Implement new tests on Project Coin
jlahoda
parents:
diff
changeset
|
49 |
public void m(AutoCloseable r); |
627464b87753
8080641: JEP-JDK-8042880 : Implement new tests on Project Coin
jlahoda
parents:
diff
changeset
|
50 |
} |
627464b87753
8080641: JEP-JDK-8042880 : Implement new tests on Project Coin
jlahoda
parents:
diff
changeset
|
51 |
|
627464b87753
8080641: JEP-JDK-8042880 : Implement new tests on Project Coin
jlahoda
parents:
diff
changeset
|
52 |
public static void close1() { } |
627464b87753
8080641: JEP-JDK-8042880 : Implement new tests on Project Coin
jlahoda
parents:
diff
changeset
|
53 |
|
627464b87753
8080641: JEP-JDK-8042880 : Implement new tests on Project Coin
jlahoda
parents:
diff
changeset
|
54 |
public void close2() { } |
627464b87753
8080641: JEP-JDK-8042880 : Implement new tests on Project Coin
jlahoda
parents:
diff
changeset
|
55 |
} |