Tag: 文字

Kotlin有一个Map语法的语法吗?

在JavaScript中: {foo: bar, biz: qux} 。 在Ruby中: {foo => bar, biz => qux} 。 在Java中: HashMap<K, V> map = new HashMap<>(); map.put(foo, bar); map.put(biz, qux); 肯定Kotlin可以比Java更好吗?

打开一个字节

如何打开Byte值? 显而易见的方法是: fun foo(b: Byte): Boolean { return when(b) { 0 -> true else -> false } } 但在编译时失败 src/ByteSwitch.kt:3:5: error: incompatible types: kotlin.Int and kotlin.Byte 0 -> true ^ 有没有办法使0是一个字节文字?