Posts & articles relating to the Java programming language or the JVM.
Recently, there were some interesting discussions about
amber-spec-expertsmailing list (1, 2) which has lead me to implement both methods with a very clear & typesafe way, which I’d like to discuss below. The code demonstrated below is available as Gist.
When reading about records and having read Pattern Matching for Java, Gavin Bierman and Brian Goetz, September 2018, it would be easy to assume that pattern matching in
instanceofwould also include deconstruction patterns. This isn’t a preview feature in Java 14 which included records via JEP 359, but was slated for Java 15 with JEP 384. Unfortunately, this JEP has changed and deconstruction patterns are no longer planned for that JEP. Records will be re-previewed as-is.
A look at the constructors of records in Java 14, and how one can leverage the formal parameter list of records to already enable libraries like Jackson to work with records (and in this example, deserialize JSON to records).
Records are sometimes described as immutable, which is unfortunate. Looking at the JEP, we see them being called “shallowly-immutable”. That is an important distinction. A record can still be changed in a multitude of ways, and this article sheds some light on the strategies one can employ to ensure records actually are immutable.
Programs often have to deal with less then ideal conditions – intermittent internet connections, hardware dropping in and out, user input not being reliable, files being corrupted, and many, many more scenarios in which failure is not only a possibility, but to a certain has to be expected and worked with without fatally crashing the application, but instead gracefully resuming and informing the user of the problems and allowing them to fix them.
In this article, I’ll talk about the following three ways to handle failure modes.
Even though Java 8 is just a little over six years old and brought a tremendous revolution to Java, adoption of lambdas and functional approaches to programming problems is still an ongoing process.
I have introduced numerous people to functional-style programming & lambdas, and at one point came up with the idea of a small “cheat sheet” only one or two DIN A4 pages in size that you could have in hand when thinking about functional stuff. This is by no means meant to be a comprehensive introduction, but a small reference document, and has been received very well, so I thought I’d share it here.