| ▲ | lmm 8 hours ago | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
> They have added proper algebraic data types to the language No they haven't. E.g. they added a class that superficially looks like Option but subtly breaks the rules that Option is meant to follow, ensuring that no-one can ever manage to migrate existing codebases away from using `null`. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ▲ | gf000 7 hours ago | parent | next [-] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Sealed classes/interfaces and records are proper sum and product types. The stdlib's Option type predates this language update by a long shot, so it doesn't use sealed classes, but it is now possible to have the usual FP "Maybe" type in Java: ``` sealed class Maybe<T> permits Some, None { record Some<T>(T obj) {} record None() {} } ``` (You will probably have to write Maybe.Some and I might have messed up the generic syntax as I wrote it on my phone, but that's mostly how it looks) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ▲ | an hour ago | parent | prev | next [-] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| [deleted] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ▲ | _kidlike 8 hours ago | parent | prev [-] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
optional is not how algebraic data types are implemented in Java. Basically it's the combination of sealed types and records. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||