Experience Report using various Project Amber Features

Donald Raab donraab at gmail.com
Sun Apr 26 22:22:30 UTC 2020

Hi All,

I wanted to share our recent experience upgrading several OSS code katas to Java 14 with this group. We will continue leveraging new Project Amber and other OpenJDK project features in these katas when we find opportunities to. Overall, our experience has been quite positive. 

Here’s a link to the collection of katas, all of which are now compiling with Java 14. The katas started out on Java 8, and were upgraded to Java 10 two years ago. We just upgraded to Java 14 a few weeks ago. 

https://github.com/BNYMellon/CodeKatas <https://github.com/BNYMellon/CodeKatas>

We tagged the repo with “Java-14” on GitHub to make the Java 14 examples easy for developers to find.

https://github.com/topics/java-14 <https://github.com/topics/java-14>

The specific Project Amber features we are using in the katas are:

1. Local Variable Type Inference

We have experimented with using the LVTI feature throughout the katas since Java 10 was released. This feature did not make a huge impact in terms of readability in the kata code itself but did prove useful in some cases. With the Java 14 upgrade, we introduced a proof of concept collections framework in the Deck of Cards Kata that adds eager APIs mirroring Stream protocols directly collection interfaces. The APIs we built in the proof of concept are implemented via default methods in the interfaces. Here for the first time, I was finally able to experiment with using LVTI in library code. This had a positive impact on the readability of the the library code IMO. This makes me wonder how much LVTI is being leveraged for good benefit in the JDK code itself. 

https://github.com/BNYMellon/CodeKatas/blob/master/deck-of-cards-kata/src/main/java/bnymellon/codekatas/deckofcards/custom/collections/MutableList.java <https://github.com/BNYMellon/CodeKatas/blob/master/deck-of-cards-kata/src/main/java/bnymellon/codekatas/deckofcards/custom/collections/MutableList.java>
https://github.com/BNYMellon/CodeKatas/blob/master/deck-of-cards-kata/src/main/java/bnymellon/codekatas/deckofcards/custom/collections/CustomCollectionsDeckOfCardsAsList.java <https://github.com/BNYMellon/CodeKatas/blob/master/deck-of-cards-kata/src/main/java/bnymellon/codekatas/deckofcards/custom/collections/CustomCollectionsDeckOfCardsAsList.java>

2. Records

I tried leveraging records with Card class in the Deck Of Cards Kata. This worked out well and delivered the savings I had expected. Kudos!

https://github.com/BNYMellon/CodeKatas/blob/master/deck-of-cards-kata/src/main/java/bnymellon/codekatas/deckofcards/Card.java#L30 <https://github.com/BNYMellon/CodeKatas/blob/master/deck-of-cards-kata/src/main/java/bnymellon/codekatas/deckofcards/Card.java#L30>

I will look to use the record feature in the Donut Kata as well for implementing the Donut Class.

3. Pattern Matching for instanceof

This feature worked out great. Well done!

https://github.com/BNYMellon/CodeKatas/blob/master/deck-of-cards-kata/src/main/java/bnymellon/codekatas/deckofcards/custom/collections/MutableCollection.java#L24 <https://github.com/BNYMellon/CodeKatas/blob/master/deck-of-cards-kata/src/main/java/bnymellon/codekatas/deckofcards/custom/collections/MutableCollection.java#L24>

As an OSS library developer, it is not often I get to use the latest available features in production library code, as providing compatibility to our existing client base which remains mostly on Java 8 makes it impossible. It was a pleasure leveraging these new features in the katas.   


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.java.net/pipermail/amber-spec-experts/attachments/20200426/e4caff5d/attachment-0001.htm>

More information about the amber-spec-experts mailing list