Return to site

Modern Java toys that boost productivity, from type inference to text blocks

· java

Local variable type inference

Removes redundant code and saves a lot of typing.


  • The takeWhile() operation processes the items of a collection and keeps each one while a given condition is true.
  • The dropWhile() operator does the opposite: It disregards the items of a collection while the predicate is true.

Switch expressions

Java 12 introduced switch expressions, which enable you to use switch to directly assign a value to a variable.


Records are great for simple classes that only need to contain fields and access to those fields.

Text blocks

It allows you to use three quotation marks to open and close a big block of text.