I just played around with the `kotlinc` REPL, and ...
# announcements
h
I just played around with the
kotlinc
REPL, and pretty quickly got a crash while doing this:
Copy code
>>> data class Node<T>(var prev: Node<T>?, var next: Node<T>?, val data: T)
>>> val first = Node(null, null, "foo")
>>> val next = Node(first, null, "bar")
>>> first.next = next
>>> first
exception: java.lang.StackOverflowError
	at Line_2$Node.toString(Line_2.kts)
	at java.lang.String.valueOf(String.java:2994)
	at java.lang.StringBuilder.append(StringBuilder.java:131)
Is there some way to make the built-in
toString
detect these kinds of loops, or do I need to create my own for these kinds of structures?
k
You'll have to roll your own.