Alexander Maryanovsky
06/01/2022, 5:33 PMval evenCount = listOf(1, 2, 3).sumOf { if (it % 2 == 0) 1 else 0 }
says sumOf
is ambiguous (can’t decide between a version that returns Int and one that returns Long), but this compiles fine:
val evenCount = listOf(1, 2, 3).sumOf { 0 + if (it % 2 == 0) 1 else 0 }
ephemient
06/01/2022, 6:04 PMAlexander Maryanovsky
06/01/2022, 7:22 PMephemient
06/01/2022, 7:24 PM1
are not Int
or Long
, but a sort of magical union type that can be treated as either Int
or `Long`: https://kotlinlang.org/spec/kotlin-spec.html#the-types-for-integer-literalsAlexander Maryanovsky
06/01/2022, 7:32 PMAlexander Maryanovsky
06/01/2022, 7:33 PMval n: Long = 5
but not
val d: Double = 4f
ephemient
06/01/2022, 7:33 PMephemient
06/01/2022, 7:35 PMbyteArrayOf(1, 2, 3)
to work without having to add an explicit .toByte()
on each literal (as there's no character suffix for byte/short)Fleshgrinder
06/02/2022, 5:51 AMephemient
06/02/2022, 9:38 AM1
is byte|short|int|long to match context) but with more type inference Kotlin has more challengesephemient
06/02/2022, 9:40 AMB
overlaps with hexadecimal. Rust-like i8/i16/etc. maybe… 🤔Fleshgrinder
06/02/2022, 11:26 AM