https://kotlinlang.org logo
Title
j

jeggy

06/20/2022, 8:00 AM
Is this considered a bug or am I really required to specify that it's an
Int
and not a
Long
?
v

Vampire

06/20/2022, 8:06 AM
I guess as soon as you use it (assign it, give it as argument, ...) the ambiguity resolves.
j

jeggy

06/20/2022, 8:09 AM
maybe I just hit a rare case 😛
val myString = """hello(value: "something")"""
val invalid = (myString.sumOf { if(it == '"') 1 else 0 } % 2) != 0
I decided to just make them
Long
's as it's easier to write an
L
behind the numbers
I have written a simple parser and was using
sumBy
but this function has been deprecated, but moving to
sumOf
brought this issue.
t

Tobias Suchalla

06/20/2022, 9:15 AM
FYI, there is
String.count
, i.e.:
val invalid = (myString.count { it == '"' } % 2) != 0
This also resolves the ambiguity :D
👍 2