The need for ! operator seems verbose


#1

Hi,

I am a novice user on Kotlin, so perhaps it’s just me not getting used to the language syntax, but when I try to integrate with existing Java libraries, I can’t but notice many forced usage of “!!.” operators all over the places, and it obstruct code reading.

Another way from doc is to use “if (var != null)”, but it’s so verbose, I don’t want to use it.

I understand there is an article says to use jetbrian’s @NotNull annotation to supress this, but it seems applicable to IDEA IDE only. This doesn’t sound like an good option to me.

So is this how Kotlin intend to be used when integrating with Java? I understand and see the good purpose of Non-NULL feature of Kotlin, but enforcing this on exiting Java library is very annoying to me. Is it just my inexperience with Kotlin, or other users feel the same?

Thanks,
Zemian


#2

Hi Zemian,

Having watched some of the talks, I’ve heard that Jetbrains is working on tooling so that annotating existing Java libraries won’t be necessary. It will inspect the byte code and determine if the types are nullable or not.

The !! operator is purposefully verbose, but once the tooling is in place, I don’t imagine it would be often necessary.

Nathan.


#3

Thank you for the links Nathan. I will check them out.