Does extending a sealed class cause recursion

58 Views Asked by At
sealed class MySealedClass {
  data class MyDataClassInsideSealed(): MySealedClass()
}

Wouldn't this cause an infinite loop?

1

There are 1 best solutions below

0
On

No, this does not cause an infinite loop. A sealed class is abstract by itself, it cannot be instantiated directly. Therefore it doesn't really contain itself, in the way you are thinking.