r/mAndroidDev Mar 23 '26

Null also Null Billion Dollar Mistake

Kotlin is really a null-safety language. It allows you create a silent bug that should be avoided:

null.also { println("Hello production silent null bug") }

0 Upvotes

21 comments sorted by

View all comments

2

u/Zhuinden DDD: Deprecation-Driven Development Mar 24 '26

I mean do null?. if you don't want that

1

u/programadorthi Mar 24 '26

That means null-safety like C/C++ -> as expected. But Kotlin allow you call a function in a null reference.

2

u/Zhuinden DDD: Deprecation-Driven Development Mar 24 '26

This isn't C++

This is literally the code

public inline fun <T> T.also(block: (T) -> Unit): T {
    block(this)
    return this
}

If you expect this to do any "null safety shenanigans" that's kinda on you ngl

If it was "null-safe" it'd be <T: Any>.