Skip to content

Instantly share code, notes, and snippets.

@struberg
Created September 21, 2016 12:40
Show Gist options
  • Save struberg/4be74fcda608178e20549331779a10e5 to your computer and use it in GitHub Desktop.
Save struberg/4be74fcda608178e20549331779a10e5 to your computer and use it in GitHub Desktop.
Java bytecode coercion with Java9 and the --release option
import java.util.concurrent.ConcurrentHashMap;
public class Test {
public static void main(String[] args) {
ConcurrentHashMap<String, String> map = new ConcurrentHashMap<>();
map.put("A", "B");
map.keySet();
}
}
Java8 and 9:
$> javac Test.java
$> javap -c Test.class
18: invokevirtual #7 // Method java/util/concurrent/ConcurrentHashMap.keySet:()Ljava/util/concurrent/ConcurrentHashMap$KeySetView;
(note the KeySetView which only got introduced in Java8!)
Java7 compatibility:
$> javac --release 7 Test.java
$> javap -c Test.class
18: invokevirtual #7 // Method java/util/concurrent/ConcurrentHashMap.keySet:()Ljava/util/Set;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment