7. JEP 286: LOCAL-VARIABLE TYPEJEP 286: LOCAL-VARIABLE TYPE
INFERENCEINFERENCE
aka var
its not a keyword
only the right-hand side is considered
Everybody say non-denotable type with
me
8. EXAMPLESEXAMPLES
var list = new ArrayList<String>();
var map = new HashMap<String, Integer>();
for (var entry : map.entrySet()) {
var key = entry.getKey();
var value = entry.getValue();
}
var now = Instant.now(); // good - Instant type is obvious
9. LEARN FROM OTHERSLEARN FROM OTHERS
If you know people using C#, scala or any
other language that have type inference for ages
ask them what they do and why
do not use var for primitive types
do not use var if the type is not obvious
factory methods like Instant.now() and
UUID.randomUUID() are ok.
10. LEARN FROM ORACLELEARN FROM ORACLE
http://openjdk.java.net/projects/amber/LVTIstyle.html
12. JEP 310: APPLICATION CLASS-JEP 310: APPLICATION CLASS-
DATA SHARINGDATA SHARING
reduce memory footprint
improve startup time
custom (app) class
loaders
-XX:+UseAppCDS
13. CREATE CLASS LIST FOR APPCDSCREATE CLASS LIST FOR APPCDS
Generates a simple text file (class name per line)
java -Xshare:off -XX:+UseAppCDS
-XX:DumpLoadedClassList=classes.lst
-cp CLASSPATH demo.App
15. USE APPCDSUSE APPCDS
On production use -Xshare:auto
java -Xshare:on -XX:+UseAppCDS
-XX:SharedClassListFile=classes.lst
-XX:SharedArchiveFile=classes.jsa
-cp CLASSPATH demo.App
16. TROUBLESHOOTINGTROUBLESHOOTING
classpath mismatch - classpath during -
Xshare:dump must be the same as, or be a prefix
of, the classpath during -Xshare:on. Use -
Xlog:class+path=info to analyze the error.
JVM may fail to map the memory file (e.g. ASLR). For
such cases using -Xshare:auto is recommended.
list classes loaded from AppCDS archive -
Xlog:class+load=info
17. WHAT’S MISSINGWHAT’S MISSING
non standardized archive storage
format
no support for --module-path yet
in oracle jdk its still commercial feature
20. JVMCIJVMCI
Run Java Bytecode with Java Bases JIT Compiler
... that optimizes itself ;)
How cool is that?
-XX:+UnlockExperimentalVMOptions
-XX:+UseJVMCICompiler
https://github.com/oracle/graal