Answer is probably no but is there a way to either...
# announcements
k
Answer is probably no but is there a way to either • reset a lateinit property back to null? • do it myself with a getter that returns non-null with
!!
and a setter that accepts null?
r
You could do that pretty simple with a delegate
k
Really? If you can't even do it by manually writing getter and setter how would a delegate do it?
Unlesss you mean actually keeping the delegate object around and calling a
reset()
function on that, but that's super awkward.
l
@karelpeeters Have a nullable
var
, and an
inline val
that gets the
var
with
!!
r
Yeah, I guess I didn't think that through all the way
k
@louiscad I'll have to resort to something like that, still annoying.
@Ruckus Haha that was my first reaction too: "I'll just write a delegate for it".
😁 1
l
@karelpeeters You can also declare a
.toPlatformType()
extension function that returns the inferred type from a generic static java method. It doesn't work outside Kotlin/JVM though.
k
Copy code
public class JavaClass {
    public static <T> T platform() {
        return null;
    }
}

public class KotlinTest {
    val x = JavaClass.platform<Int>()
}
makes
x: Int!
. Damm that is evil.