I had a problem yesterday with a linked data-structure that looked like this:
class ItemRow(private val nextRow: ItemRow?) {
fun pushOverflow(width) {
// work on this row
nextRow?.pushOverflow(width)
}
}
The last line quickly lead to a stack-overflow. I solved it by calling the method from outside, but is there a way to mark this function as tail-recursive?
Is there a way to use an extension method instead? That would essentially be a single function, so it could be made tail recursive. It doesn’t allow you to use inheritance, but it doesn’t look like you are anyway.