herder
08/08/2017, 6:13 AMkotlinc
REPL, and pretty quickly got a crash while doing this:
>>> 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?karelpeeters
08/08/2017, 7:14 AM