Java

Posts & articles relating to the Java programming language or the JVM.

  • Record#with - a thought experiment

    Recently, there were some interesting discussions about Record#copy() and Record#with(...) on the amber-spec-experts mailing 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.

  • A small side note on JEPs 384 and 359

    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 instanceof would 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.

  • Records & their constructors

    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).

  • On records & (im-) mutability

    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.

  • Failure Modes

    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.

  • Java 8 Lambda Cheat Sheet

    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.