``` class Env { fun sub() = SubEnv(this) } cl...
# announcements
k
Copy code
class Env {
    fun sub() = SubEnv(this)
}

class SubEnv(val parent: Env)
Is there a nice way to make
sub()
the only possible way to construct a
SubEnv
instance? Making the constructor of
SubEnv
private
isn't allowed. Making
SubEnv
an inner class doesn't help either, you're still not allowed to make the constructor private.
s
Make
SubEnv
an interface or sealed baseclass and make
SubEnvImpl
private
k
Yeah I was afraid I'd have to do that 😕