Kotlin: Hacking non Null variable Null!!

One of Kotlin most prominent feature above Java is it’s null-safety feature. However, there’s a simple way that make it null, and the code still executable.

Don’t believe? Try the below code.

@Test
fun forceNull() {
val nullBody = """{ "nonNull" : null}"""
val nullNonNull = Gson().fromJson(nullBody, MyData::class.java)
System.out.println(nullNonNull)
}…

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store