Why does array[idx++]+=”a” increase idx once in Java 8 but twice in Java 9 and 10?

This is a bug in javac starting from JDK 9 (which made some changes with regard to string concatenation, which I suspect is part of the problem), as confirmed by the javac team under the bug id JDK-8204322. If you look at the corresponding bytecode for the line: array[i++%size] += i + ” “; It … Read more

How to convert a Java 8 Stream to an Array?

The easiest method is to use the toArray(IntFunction<A[]> generator) method with an array constructor reference. This is suggested in the API documentation for the method. String[] stringArray = stringStream.toArray(String[]::new); What it does is find a method that takes in an integer (the size) as argument, and returns a String[], which is exactly what (one of … Read more

:: (double colon) operator in Java 8

Usually, one would call the reduce method using Math.max(int, int) as follows: reduce(new IntBinaryOperator() { int applyAsInt(int left, int right) { return Math.max(left, right); } }); That requires a lot of syntax for just calling Math.max. That’s where lambda expressions come into play. Since Java 8 it is allowed to do the same thing in … Read more

How to install Java 8 on Mac

Oracle has a poor record for making it easy to install and configure Java, but using Homebrew, the latest OpenJDK (Java 14) can be installed with: brew install –cask adoptopenjdk8 For the many use cases depending on an older version (commonly Java 8), the AdoptOpenJDK project makes it possible with an extra step. brew tap … Read more

tech