I had recently discovered the JDK 8's addition of the Optional type. The Optional type is a way to avoid NullPointerException, as API consumers that get Optional return values from methods are "forced" to perform "presence" checks in order to consume their actual return value. More details can be seen in the Javadoc. A very … Continue reading On Java 8’s introduction of Optional
Tag: language java
JDK 8: State of the Collections
Here's the latest publication by Brian Goetz, Oracle's project lead for JSR 335, a.k.a. Project Lambda. Here's a nice example showing new collection features, such as "Streams" using method references: List<String> strings = ... int sumOfLengths = strings.stream() .map(String::length) .reduce(0, Integer::plus); Another nice example showing the use of lambda expressions: int sum = shapes.stream() .filter(s … Continue reading JDK 8: State of the Collections
Array, list, set, map, tuple, record literals in Java
Occasionally, when I'm thrilled by the power and expressiveness of JavaScript, I find myself missing one or two features in the Java world. Apart from lambda expressions / closures or whatever you want to call "anonymous functions", it's the use of advanced literals for common data types, such as arrays, lists, sets, maps, etc. In … Continue reading Array, list, set, map, tuple, record literals in Java
if – else coding style best practices
The following post is going to be an advanced curly-braces discussion with no right or wrong answer, just more "matter of taste". It is about whether to put "else" (and other keywords, such as "catch", "finally") on a new line or not. Some may write if (something) { doIt(); } else { dontDoIt(); } I, … Continue reading if – else coding style best practices