Java’s Checked Exceptions Are Just Weird Union Types

This fun fact has been on my mind for a while, and a recent reddit thread about "Smuggling Checked Exceptions with Sealed Interfaces" made me write this post here. Namely, Java had union types before it was cool! (If you squint hard). What are union types? Ceylon is an underrated JVM language that never really … Continue reading Java’s Checked Exceptions Are Just Weird Union Types

How Functional Programming will (Finally) do Away With the GoF Patterns

A recent article about various ways to implement structural pattern matching in Java has triggered my interest: http://blog.higher-order.com/blog/2009/08/21/structural-pattern-matching-in-java The article mentions a Scala example where a tree data structure can be traversed very easily and neatly using Scala's match keyword, along with using algebraic data types (more specifically, a sum type): def depth(t: Tree): Int … Continue reading How Functional Programming will (Finally) do Away With the GoF Patterns

An Ingenious Workaround to Emulate an Application of Union Types in Java

Before I move on with the actual article, I'd like to give credit to Daniel Dietrich, author of the awesome vavr library, who has had the idea before me: https://twitter.com/danieldietrich/status/699633269202149377 Contravariant Generic Bounds It all started with a tweet: https://twitter.com/lukaseder/status/699588908095508480 I wanted to do something like pattern-matching a common super type of a set of … Continue reading An Ingenious Workaround to Emulate an Application of Union Types in Java