Browsing posts in: convertoToKotlin

What the heck is “!!” and “??” in Kotlin

One of the first things that I found as I am starting my process of converting to Kotlin is the single and double exclamation mark “!” and the single and double question mark “?”. The first thing I thought about was, “mmmm, i think i have seen this some where before and I am like aha! I saw this in Swift” Swift has something like that too, the question mark “?” and the exclamation mark “!”. Where you tell the system that null is expected or not expected. I have not used Swift for sometime but this was awesome to have so that you can avoid null pointer exceptions while running your app. The last thing you need to know that some one places a 1 star review on Google Play Store that your app is “crashing”! To be honest, I was feeling jealous that Swift developers had this kind of advantage over android developers. There are many things that I feel they have more advantages but let’s not go too deep now!

Of course Java does not have this ! However it can be done using @Nullable annotations. So you need to use this annotation anywhere you have to use it to declare a variable or object that it can be Null. You know what, I liked the fact that now in Android development you can use the !! or ?? marks which is cleaner and comes inline with the code.

The Null Pointer Exception has been one of Kotlin’s top priorities in order to overcome Java and to convince developers to convert to Java.