Second question - if I write `val foo = 0x1u` it's...
# announcements
Second question - if I write
val foo = 0x1u
it's treated as
. Is there a way to make it something else without providing a type? For example:
Copy code
val foo: UByte = 0x1u

when(foo) {
    0x1u -> {} // doesn't work because 0x1u is treated as an Int
I can do
but it's ugly. Is there maybe something like
suffix or sth like that?
No, there can't be. One downside of type inference (in any language) is that primitive (or potentially any "built in") values can be ambiguous, so a default has to be chosen. For integral types, it's
suffix). it's the same reason
val x = 5
doesn't create a
unless you specify.
Instead of using
on the literal, you could try using
on foo to see if you like that more.
Copy code
val foo: UByte = 0x1u

when (foo.toUInt()) {
    0x1u -> ...
Makes sense, not sure if adding unsigned types to Kotlin was worth the effort. It's still a pain to code low level stuff that operates on bytes and bits.
You should realize that adding support for unsigned types wasn't the end goal, just the first step in a long (and ongoing) story. There are a number of ongoing discussions about the best way to implement operators for the various primitive types, as well as improving the whole bit fiddling experience (and lots of other low level type stuff). Hopefully it will get MUCH better with time as more of the story plays out.
­čĹŹ 1