Consider the example below:
class MyList<T> {
val size: Int get() = TODO()
fun iterator() = MyListIterator(0, 1)
fun reversedIterator() = MyListIterator(size - 1, -1)
inner class MyListIterator /* private */ constructor(var cursor: Int, val step: Int) {
fun next(): T = TODO()
fun previous(): T = TODO()
}
}
I want to define some factory methods to construct instances for nested class, to be more semantic. And hide the construct itself as an “implementation detail”.
Currently it’s not possible in Kotlin unless define a separate interface and hide the whole nested class, or define the constructor internal.
I’m curious why in Kotlin classes can’t access private members of its nested classes. As in Java, they can.