Hi,
I am actually using kotlin 1.4.10 and am missing a feature?
It is needed for structuring issues (hope so, that’s the right word). For example:
class MyTestData (val foo: Foo) // dependencies
{
inner object case1 {
val bar = foo.bar()
}
inner object case2 {
val bar = foo.someOtherBar()
}
}
...
// somewhere
val data = MyTestData(FakedFoo())
assertEquals(data.case1.foo, ...)
With object alone it is not possible to access foo. “inner object” does not exist. Is it possible to get this feature in some future version?
I am asking, because there exist “inner class” and an “inner object” would be nice …
You can declare a private inner class with the behaviour you want, and then have a field of that type.
class MyTestData (val foo: Foo)
inner class Case1_ {
val bar = foo.bar()
}
val case1 = Case1_()
}
The reason for inner object not to exist is that it’s confusing imho, object instances are singletons, in your case you’d have an instance of each of these inner objects for each instance of MyTestData.