Migrating from Java 8 to Java 17 II: Notable API Changes Since Java 8
igorstechnoclub.com
igorstechnoclub.com
What is it with Java deciding "Why use 2 characters when 40 will do?" Is it to much to ask for a ?? or ?: operator?
List<String> trimAndAdd(List<String> input, String newItem) {
List<String> result = new ArrayList<>(input.size() + newItem == null ? 0 : 1);
... Objects.requireNonNullElse(str, "default")
or even worse, if you need the right-hand side to be evaluated lazily: Objects.requireNonNullElseGet(str, () -> "default")
while Javascript's null-coalescing operator allows writing this so much simpler: str ?? "default"
str ?? getDefault()
(And not to mention the fact that the null-coalescing operator can also be used for conditional assignment, for which Java has no option at all!)Personally I learned Java 7 when it was the latest, then stuck with it since. I'd prefer to continue on with the same thing, there's more depth than one person can learn anyway, than add more things.
These things look nice, but they're mainly add-on bits. The core language is still the same. Though streams are a bit more special.
Honestly I would not recommend anybody migrate from 8 to 17 anyway. 8 to 11 or 8 to 21 are much better choices, depending on your appetite for migration pain.
For example where previously you could override a class by simply putting a different library ahead of the normal element in the classpath that resolves it, with modules, Java will respect the declared module dependencies. As another example, reflection is prevented from resolving things from other modules that are not exported, where previously reflection could resolve everything.
These things can be worked around and people will argue they are things you should not have relied on in the first place, but the reality is very many useful libraries did and very often the "fixed" version is only available with a new major version of the library. So you can quickly find that just moving to Java 9+ means upgrading your entire dependency tree.