I am trying to figure out how to use algebraic data types in Kotlin, so I\'m trying to implement a basic BinaryTree type the following way.
sealed class Tree<
First you need to make T an out parameter. Then you can use Nothing as a type argument for Empty.
sealed class Tree{
class Node(val left: Tree, val right: Tree): Tree()
class Leaf(val value: T): Tree()
object Empty: Tree()
}
Nothing is a special type in Kotlin, which cannot have an instance and is a subtype of all other types. So I would say it's opposite to Any in Kotlin type hierarchy.