Java Magazine, May/June 2018
var and Java 10 s Expanded Type Inference Best practices for using local variable type inference ORACLE COM JAVAMAGAZINE MAY JUNE 2018 63 java 10 Java 10 introduced a new shiny language feature called local variable type inference Its principal goal is to reduce boilerplate and enhance code readability It enables you to replace the type in a local variable declaration with the keyword var the compiler fills in the appropriate type from the variable initializer For example this code Map User List String userChannels new HashMap can be rewritten in Java 10 as var userChannels new HashMap User List String In addition to concision this inference of the type provides several advantages which we explore in this article Lets look at a more involved example Path path Paths get src web log try Stream String lines Files lines path long warningCount lines filter line line contains WARNING count System out println Found warningCount warnings in the log file catch IOException e RAOUL GABRIEL URMA RICHARD WARBURTON
You must have JavaScript enabled to view digital editions.