https://kotlinlang.org logo
#getting-started
Title
# getting-started
d

dave08

11/09/2021, 2:32 PM
Why aren't
data
and
inner
modifiers to
class
compatible together?
j

Joffrey

11/09/2021, 2:33 PM
I have never given it much thought, but I'd be interested in knowing your use case for needing both
d

dave08

11/09/2021, 2:36 PM
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

ephemient

11/09/2021, 7:47 PM
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

dave08

11/09/2021, 8:22 PM
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

ephemient

11/11/2021, 1:23 AM
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 }
2 Views