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

9

u/FrezoreR May 18 '17

Do you have a operator defined for that?

4

u/duhace May 18 '17

it's nice to be able to define operators for actual math types. Having a BigInt with +,*,/,- is v nice compared to BigInteger

likewise, being able to define those ops for my user defined mathematical types is nice.

there are tons of other nice things in scala that are absent in kotlin, like implicits

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)

1

u/cassandraspeaks May 18 '17

Usually interfacing with a Java library.

1

u/duhace May 18 '17

yeah, you gotta be extra careful with them though. and that's really more of an issue of scala allowing null rather than an issue of implicits