Skip to content

Commit a1289c6

Browse files
committed
MethodHandleTest++
MethodHandleTest++
1 parent d65c984 commit a1289c6

File tree

4 files changed

+59
-16
lines changed

4 files changed

+59
-16
lines changed

src/main/java/com/inbravo/jdk7/MethodHandleTest.java

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ public static final void main(final String... args) throws Throwable {
2525

2626
@SuppressWarnings("unused")
2727
private static final void hello() {
28+
2829
System.out.println("hello");
2930
}
3031
}

src/main/java/com/inbravo/jdk7/SafeVarargsAnnotationTest.java

+22
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,25 @@
1+
/*
2+
* MIT License
3+
*
4+
* The Java '@SafeVarargs' annotation
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.
22+
*/
123
package com.inbravo.jdk7;
224

325
import java.util.ArrayList;

src/main/java/com/inbravo/jdk9/UnderscoreAsIdentifierTest.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
package com.inbravo.jdk9;
2525

2626
/**
27-
* Oracle has removed underscore (“_”) usage as identifier completely in Java SE 9 release
27+
* Oracle has removed underscore ('_') usage as identifier completely in Java SE 9 release
2828
*
2929
* @author amit.dixit
3030
*/
@@ -34,7 +34,7 @@ public static void main(final String... args) {
3434

3535
final String stringWithoutUnderscore = "stringWithoutUnderscore";
3636

37-
/* Line below will give error */
37+
/* Will give error '' should not be used as an identifier, since it is a reserved keyword from source level 1.8 on' */
3838
/* final String _ = "stringWithUnderscore"; */
3939
/* System.out.println("stringWithUnderscore : " + _); */
4040
System.out.println("stringWithoutUnderscore : " + stringWithoutUnderscore);
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,24 @@
11
/*
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.
522
*/
623
package com.inbravo.jdk9;
724

@@ -14,19 +31,22 @@
1431
* @author amit.dixit
1532
*/
1633
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);
2743
}
44+
}
2845
}
2946

47+
48+
/* A non static nested class = Inner Class 'Foo' */
3049
class Foo {
31-
public final int i = 10;
50+
51+
public final int i = 10;
3252
}

0 commit comments

Comments
 (0)