4 ms·
If you type everything with interfaces in your codebase, you are much less tied to inheritance. In fact, everyone could be written to be composed. However Java
by wayfinder 3y ago
If you type everything with interfaces in your codebase, you are much less tied to inheritance. In fact, everyone could be written to be composed.
However Java doesn’t support type union so you can get into some ugly and verbose situations but the JVM doesn’t really check type so this is more a compile-time issue and could be fixed in a future Java language revision.
- logicchains 3y ago>However Java doesn’t support type union so you can get into some ugly and verbose situations Isn't the "sealed interface" described in the OP blog post a type union? Or you mean anonymous unions?
- wayfinder 3y agoDefinitely referring to anonymous unions too. Without them, there’s still friction sometimes which makes union types unnatural. I haven’t written Java in a while and I can’t remember if you could sometimes fake a type union using a generic type on a method, but if you can, it’s definitely super ugly and would raise eyebrows during any code review.
- logicchains 3y agoAnonymous unions are a relatively rare feature; Rust and Haskell don't have them, for instance.