Proposal: Allow `inner object` On several instance...
# language-proposals
r
Proposal: Allow
inner object
On several instances I've come across a situation where I have code like:
Copy code
class Parent {
    val child: Child = Child()

    inner class Child
}
Where it would be preferable to have:
Copy code
class Parent {
    inner object Child
}
The main advantage I'm looking for (other than readability) is locality: - Every
Parent
has in instance of
Child
-
Child
is a well defined type - You cannot create new instances of
Child
with something like
parent.Child()
👍 9
s
What about this?
Copy code
class Parent {
  val child = object { ... }
}
r
That breaks the second point, that
Child
is a defined type
k
I'd like this too, I've posted about this a couple of times in this channel before.
s
I didn't know that you cannot access functions or properties of the object outside of it. And I don't know why you can't. Is that what you mean with being a well defined type?
👌 1
h
I'm greatly in favor of this, but there may be the concern of consistency that objects within classes are always static
Haha @karelpeeters did you post about that when you were helping me design the matrix class i was working on?
k
I did, but I ran into the use case before a couple of times as well.