Ruckus
06/13/2019, 8:50 PMinner object
On several instances I've come across a situation where I have code like:
class Parent {
val child: Child = Child()
inner class Child
}
Where it would be preferable to have:
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()
SiebelsTim
06/13/2019, 8:55 PMclass Parent {
val child = object { ... }
}
Ruckus
06/13/2019, 9:15 PMChild
is a defined typekarelpeeters
06/13/2019, 10:24 PMkarelpeeters
06/13/2019, 10:28 PMSiebelsTim
06/14/2019, 6:28 AMHullaballoonatic
06/14/2019, 7:49 PMHullaballoonatic
06/14/2019, 7:52 PMkarelpeeters
06/14/2019, 10:46 PM