Is there a way to jam a null into a non-nullable type with some sort of "I know what I'm doing"?
I want to make a doubly linked list:
data class Node(var prev: Node, var next: Node, val value: Int)
I can guarantee that this list will have at least two elements at all times except during initialization, after the first node has been added but before the second node. I'd like to make the guarantee that prev and next will never be null.
One thing I thought I'd try is to write a special constructor that initializes both the first and second nodes constructor(v1: Int, v2: Int) : this(Node(this, this, v1), v2)
, but that doesn't work because I can't do anything with this
before entering the body.
by lazy
might also be an option, but AFAIK, it can't be used in the primary constructor either - Zoe