|
1 | 1 | /*
|
2 |
| - * To change this license header, choose License Headers in Project Properties. |
3 |
| - * To change this template file, choose Tools | Templates |
4 |
| - * and open the template in the editor. |
| 2 | + * MIT License |
| 3 | + * |
| 4 | + * Class 'java.lang.invoke.VarHandle' example based on JEP-193 |
| 5 | + * |
| 6 | + * Copyright (c) 2017 Onwards Amit Dixit (github.com/inbravo) |
| 7 | + * |
| 8 | + * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and |
| 9 | + * associated documentation files (the "Software"), to deal in the Software without restriction, |
| 10 | + * including without limitation the rights to use, copy, modify, merge, publish, distribute, |
| 11 | + * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is |
| 12 | + * furnished to do so, subject to the following conditions: |
| 13 | + * |
| 14 | + * The above copyright notice and this permission notice shall be included in all copies or |
| 15 | + * substantial portions of the Software. |
| 16 | + * |
| 17 | + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT |
| 18 | + * NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
| 19 | + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, |
| 20 | + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 21 | + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
5 | 22 | */
|
6 | 23 | package com.inbravo.jdk9;
|
7 | 24 |
|
|
14 | 31 | * @author amit.dixit
|
15 | 32 | */
|
16 | 33 | public class VarHandleTest {
|
17 |
| - |
18 |
| - public static void main(final String... args) { |
19 |
| - try { |
20 |
| - final MethodHandles.Lookup lookup = MethodHandles.lookup(); |
21 |
| - final VarHandle varHandle = lookup.in(Foo.class).findVarHandle(Foo.class, "i", int.class); |
22 |
| - |
23 |
| - System.out.println(varHandle); |
24 |
| - } catch (final ReflectiveOperationException e) { |
25 |
| - throw new Error(e); |
26 |
| - } |
| 34 | + |
| 35 | + public static void main(final String... args) { |
| 36 | + try { |
| 37 | + final MethodHandles.Lookup lookup = MethodHandles.lookup(); |
| 38 | + final VarHandle varHandle = lookup.in(Foo.class).findVarHandle(Foo.class, "i", int.class); |
| 39 | + |
| 40 | + System.out.println(varHandle); |
| 41 | + } catch (final ReflectiveOperationException e) { |
| 42 | + throw new Error(e); |
27 | 43 | }
|
| 44 | + } |
28 | 45 | }
|
29 | 46 |
|
| 47 | + |
| 48 | +/* A non static nested class = Inner Class 'Foo' */ |
30 | 49 | class Foo {
|
31 |
| - public final int i = 10; |
| 50 | + |
| 51 | + public final int i = 10; |
32 | 52 | }
|
0 commit comments