Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Use ULong as function parameter in Kotlin

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

My code looks like below:

import androidx.compose.ui.graphics.Color

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

Then I got an error looks like:
compiler error

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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())
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading