farmerbb
02/01/2023, 4:55 PMinit
block inside of an abstract class
🤦♂️Loney Chou
02/01/2023, 4:59 PMfarmerbb
02/01/2023, 4:59 PMAttempt to invoke interface method <name> on a null object reference
that I couldn't reproducePablichjenkov
02/01/2023, 5:11 PMfarmerbb
02/01/2023, 5:15 PMabstract class SomeAbstractClass(
scope: CoroutineScope
) {
protected abstract val someVal: SomeType
init {
scope.launch {
someVal.someFunction()
}
}
}
someVal.someFunction()
outside of the coroutine scope then the IDE warns me with Accessing non-final property <name> in constructor
but no such warning while inside the coroutine scope.Pablichjenkov
02/01/2023, 5:29 PMfarmerbb
02/01/2023, 5:30 PMGleb Minaev
02/01/2023, 6:57 PMfun exec(block: () -> Unit) { block() }
abstract class SomeAbstractClass {
protected abstract val someVal: String
init {
exec {
someVal.length
}
}
}
Pablichjenkov
02/01/2023, 7:05 PMRuckus
02/01/2023, 7:19 PMthe warning should trigger whenever a property name is found within init{}, regardless of scopeI would say no. Counter use case I run into commonly is something along the lines of
abstract class Thing<T> : Observable<T> {
abstract val value: Stuff
init {
addListener { doSomething(it, value) }
}
}
Which is perfectly valid, as the lambda will not be executed till later.Pablichjenkov
02/01/2023, 7:40 PM