This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.lang.reflect.*; | |
public class IsReflectionSlow { | |
public static double rand() { | |
return Math.random(); | |
} | |
public static String constant() { | |
return "constant"; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Set; | |
import java.util.HashSet; | |
public class Deps { | |
public static void main(String[] args) { | |
System.out.println(Math.random()); | |
Set<String> set = new HashSet<>(); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@interface Foo {} | |
interface Bar {} | |
public class Annotation { | |
public static void main(String[] args) { | |
System.out.println("Foo annotation super interfaces"); | |
for (Class<?> klazz : Foo.class.getInterfaces()) | |
System.out.println(klazz); | |
System.out.println("Bar interface super interfaces"); | |
for (Class<?> klazz : Bar.class.getInterfaces()) | |
System.out.println(klazz); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Arrays; | |
import java.time.*; | |
public class PSort { | |
public static void main(String[] args) { | |
if (args.length != 2) { | |
System.err.println("Usage: PSort [seq|par] [data size int]"); | |
System.exit(1); | |
} | |
boolean parallel = "par".equals(args[0]); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Function descriptor examples: | |
interface X { void m() throws IOException; } | |
interface Y { void m() throws EOFException; } | |
interface Z { void m() throws ClassNotFoundException; } | |
interface XY extends X, Y {} | |
interface XYZ extends X, Y, Z {} | |
// XY has descriptor ()->void throws EOFException | |
// XYZ has descriptor ()->void (throws nothing) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
println "null < ${Long.MIN_VALUE}: ${null < Long.MIN_VALUE}" | |
println "null < ${Boolean.FALSE}: ${null < Boolean.FALSE}" | |
println "false < true: ${false < true}" | |
println "null < new Object(): ${null < new Object()}" | |
println "null < null: ${null < null}" | |
def data = ["1", 2, 3L, null, "foo"] | |
println data.sort() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void m1(int x) { | |
int y = 1; | |
foo(() -> x+y); | |
// Legal: x and y are both effectively final. | |
} | |
void m2(int x) { | |
int y; | |
y = 1; | |
foo(() -> x+y); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
System::getProperty | |
String::length | |
List<String>::size // explicit class type args | |
List::size // inferred class type args, or generic | |
int[]::clone | |
T::tvarMember | |
"abc"::length | |
foo[x]::bar | |
(test ? list.map(String::length) : Collections.emptyList())::iterator |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Comparator; | |
import java.util.List; | |
import java.util.ArrayList; | |
import java.util.Arrays; | |
import java.util.Collections; | |
import java.util.stream.Collectors; | |
public class MethodReferences { | |
public static void main(String[] args) { | |
List<String> list = new ArrayList<String>(Arrays.asList("cat", null, "foo", "aces", "bar", null, "az", null, "bc")); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
interface I { | |
default String hi() { return "hello"; } | |
static String here() { return "i'm static"; } | |
// NEXT LINE WILL NOT COMPILE. But JLS8 says private default methods are allowed. | |
default private String you() { return "yoho"; } // Not implemented as of jdk8b103. | |
} | |
class C implements I { | |
} | |
public class Jvm8Changes { | |
public static void main(String[] args) { |