Use ULong as function parameter in Kotlin

Can I use ULong as a parameter in function definition in Kotlin?

My code looks like below:


fun EColor(value: ULong) = Color(value)
val Red700 = EColor(0xffdd0d3c)

Then I got an error looks like:
compiler error

Conversion of signed constants to unsigned ones is prohibited

If I call val Red700 = Color(0xffdd0d3c), then it works fine.

So how come I got this error?

>Solution :

There are unsigned literals in Kotlin. You write them by adding a u or U suffix:

val Red700 = EColor(0xffdd0d3cU)

You can also call toULong:

val Red700 = EColor(0xffdd0d3c.toULong())

Leave a Reply