https://kotlinlang.org logo
d

Daniel Svensson

09/18/2020, 6:55 AM
kotlin-test's assertNotNull lets the compiler know that whatever is passed to it is not null afterwards, while junit's assertNotNull does not. Why is it like that?
c

christophsturm

09/18/2020, 7:01 AM
its probably using contracts. look here https://kotlinlang.org/docs/reference/whatsnew13.html
p

Petter Måhlén

09/18/2020, 7:02 AM
yes
Copy code
/** Asserts that the [actual] value is not `null`, with an optional [message]. */
fun <T : Any> assertNotNull(actual: T?, message: String? = null): T {
    contract { returns() implies (actual != null) }
    asserter.assertNotNull(message, actual)
    return actual!!
}
d

Daniel Svensson

09/18/2020, 7:12 AM
Thanks a lot guys!