Why aren't `data` and `inner` modifiers to `class...
# getting-started
d
Why aren't
data
and
inner
modifiers to
class
compatible together?
j
I have never given it much thought, but I'd be interested in knowing your use case for needing both
d
I need to set up a
TestFixture
class that uses repos in the outer test class to add the fields (entities with relations) to the dbs in the
init
block... if I put the data class inside the test's init block before the tests, it has access to the test class's properties, whereas if I put it after, I have to make it into an inner class, then I can't do :
val (client, order) = TextFixture()
unless I implement my own componentX functions...
e
inner
classes work by having a extra hidden reference to the outer class, inserted into every constructor, which I suppose could be implemented on a
data
class, but feels very strange
moreover, given
Copy code
class Foo { inner data class Bar(...) }
should
Foo().Bar(...) == Foo().Bar(...)
with different outer references that aren't publicly accessible on
Bar
itself?
d
Interesting, thanks for the explanation! I still think it might be useful though... I wonder if anyone would expect those to be equal, though. I think even though i componentX and field list the outer class ref isn't there, it should still not be equal in the end.
e
makes sense but it's inconsistent with existing behavior
Copy code
data class Foo(val bar: Int) {
    var extra = 0
}
Foo(0).apply { extra = 1 } == Foo(0).apply { extra = 2 }