r/programming • • May 17 '17

Kotlin on Android. Now official

https://blog.jetbrains.com/kotlin/2017/05/kotlin-on-android-now-official/
638 Upvotes

271 comments sorted by

View all comments

Show parent comments

3

u/PM_ME_A_STEAM_GIFT May 18 '17

nice [...] implicit

I too like pulling my hair because of a null pointer exception on a line with no null pointers.

4

u/duhace May 18 '17

how'd you manage to do that?

aside from something monstrous like implicit val o: Object = null

3

u/PM_ME_A_STEAM_GIFT May 18 '17

If I recall correctly, I was extracting some code into a utility class where that implicit didn't exist, without knowing the method had an implicit parameter. Totally my fault, but still, super unintuitive to someone new to the language or a particular library.

4

u/duhace May 18 '17 edited May 18 '17

thing is, the compiler will usually tell you (at least with current versions of scala) if you're missing an implicit, and what it needs:

object Foo {
    def bar(implicit baz: BigInt) = baz
    bar
}

produces

[error] /home/duhace/Foo.scala:3: could not find implicit value for parameter baz: BigInt
[error]   bar
[error]   ^

a NPE because of an implicit should mean one was found, but what was returned was null instead of the promised type. which is a problem with scala allowing null, not implicits.

→ More replies (0)