If you have an inner class which should be instati...
# announcements
c
If you have an inner class which should be instatiated inside the class where it is declared. But the object should be accessible outside the class through some getter. How it is possible in Kotlin? If not possible, then why it is restricted in Kotlin?
d
Works just fine:
Copy code
class Outer {

    val inner = Inner()

    inner class Inner

}

fun main(args: Array<String>) {
    val outer = Outer()
    println(outer.inner)
}
c
This will also allow other classes to instantiate the inner class object like val inner = Outer().Inner() from anywhere. What I want is Inner class object should only be instantiated inside Outer class and not outside.
d
I think the best you can do is make the
Inner
constructor
internal
, so
inner class Inner internal constructor()
, but that's module-private, not class-private.