I just don't understand the difference or why one ...
# announcements
p
I just don't understand the difference or why one of them fails.
r
You’re simply not initializing
master
before
data
Remember that the constructor of the superclass is called BEFORE the constructor of any subclass, so
master
stays null during the entire execution of the abstract class constructor
This comment
I know the
get()
is unnecessary
It’s completely wrong, these two are two very different things:
Copy code
val x: Int get() = y
Copy code
val x: Int = y
p
But it crashes on access to
hash
, not during construction - or am I way out here? Note that this is an
abstract
and there
is
a
master
at that time is there not? So what is the difference and why does changing
data
make
hash
work?
Your error clearly state that
master
is null in case you didn’t see
p
Yes!
master
is
null
when I request the
hash
and that is long after the actual object has finished construction.
Copy code
object FooImageData : ImageData() {
    override val master = listOf(
        "424d3684030000000000..."
        // ...
    )
}
r
Well that’s just not possible so I’m gonna keep saying your object hasn’t finished construction yet the first time you call
hash
p
Well that’s just not possible
My feelings exactly! Which is why I chose to ask here. 🙂