Matyáš Vítek
10/26/2023, 7:51 PMFoo to the instances map under their pointer property?
abstract class Foo {
companion object {
val instances = mutableMapOf<CPointer<out CPointed>, Foo>()
}
open val pointer: CPointer<out CPointed> = something()
}
class Buzz : Foo() {
override val pointer: CPointer<out CPointed> = somethingElse()
}
I've tried adding
init {
instances[this.pointer] = this
}
to the Foo class, but I get an error (Variable 'pointer' must be initialized) and a warning (Leaking 'this' in constructor of non-final class Foo)
(and yes, I do need this...)Youssef Shoaib [MOD]
10/26/2023, 8:04 PMabstract class Foo(val pointer: CPointer<out CPointed> = something())
Then the init block approach would work I thinkMatyáš Vítek
10/27/2023, 12:32 PMthis (but I think it would be OK to suppress it this case)
I sadly omitted one extra class, which causes the need to make pointer still be open as it extends Buzz, so my actual code is
abstract class Foo {
companion object {
val instances = mutableMapOf<CPointer<out CPointed>, Foo>()
}
open val pointer: CPointer<out CPointed> = something()
init {
instances[this.pointer] = this
}
}
class Buzz : Foo(someArgument: SomeType = someValue) {
override val pointer: CPointer<out CPointed> = somethingElse()
}
class FooBar : Buzz {
override val pointer: CPointer<out CPointed> = somethingEvenDifferent()
}
and after the modification you suggested, I got to this:
abstract class Foo(open val pointer: CPointer<out CPointed> = something()) {
companion object {
val instances = mutableMapOf<CPointer<out CPointed>, Foo>()
}
init {
instances[this.pointer] = this // Accessing non-final property pointer in constructor; Leaking 'this' in constructor of non-final class Foo
}
}
class Buzz : Foo(someArgument: SomeType = someValue) {
override val pointer: CPointer<out CPointed> = somethingElse()
}
class FooBar : Buzz {
override val pointer: CPointer<out CPointed> = somethingEvenDifferent()
}Youssef Shoaib [MOD]
10/27/2023, 12:33 PMMatyáš Vítek
10/27/2023, 1:01 PMandylamax
10/27/2023, 1:48 PMMatyáš Vítek
10/27/2023, 2:13 PMandylamax
10/27/2023, 2:27 PMabstract class Foo(val pointer: CPointer<out CPointed>) {
companion object {
val instances = mutableMapOf<CPointer<out CPointed>, Foo>()
}
init {
instances[this.pointer] = this
}
}
class Buzz : Foo(something())
class FooBar : Foo(somethingElse())andylamax
10/27/2023, 2:28 PMMatyáš Vítek
10/27/2023, 2:29 PMFooBar class to extend the Buzz class 😄Matyáš Vítek
10/27/2023, 2:29 PMBuzz class tooandylamax
10/27/2023, 2:35 PMMatyáš Vítek
10/28/2023, 8:51 AMWindow is Buzz and ApplicationWindow is FooBar)
Whenever I try to create a new instance of ApplicationWindow, the pointer that is saved there is null, if I try to retrieve the pointer property after initialization, it's not nullMatyáš Vítek
10/28/2023, 8:52 AMMatyáš Vítek
10/28/2023, 9:05 AMpointer as an argument, making the constructor internal and creating a builder function 😌