`1b` can be confused with hexadecimal literal
# language-proposals
i
1b
can be confused with hexadecimal literal
i
How's that, they have to start with
0x
, do they not? (https://kotlinlang.org/docs/reference/grammar.html#HexadecimalLiteral)
i
Even if we could distinguish these values by
0x
prefix, it would be confusing. And in fact we can't:
val x: Byte = 0x1b
is a perfectly valid hexadecimal literal byte value (27)
i
Not sure I follow the ambiguity here.
Copy code
val a = 1b // Byte, 0b0000_0001
val b = 27b // Byte, 0b0001_1011
val c = 0x1b // Int, 0b0001_1011
val d: Byte = 1b // Byte, 0b0000_0001
val e: Byte = 0x1b // Byte, 0b0001_1011
All the same, 'y/Y' could be used instead: http://mail.openjdk.java.net/pipermail/coin-dev/2009-March/000905.html
b
0b
also looks like a dangling beginning of a binary literal, like
0b101
i
@ianbrandt So, do you propose not to have hexadecimal literals with the byte suffix, right? That wouldn't be consistent either. For example one can write
val long = 0x1L
now, and then he would expect being able to change
L
to
b
to have the literal typed as
Byte
, but instead it would become an
Int
with a completely different value.
i
@ilya.gorbunov, Good one. Sold. 'y/Y' then?