【发布时间】:2018-04-01 14:15:52
【问题描述】:
如何将 Ceylon 中的字符串编码为 UTF-8 字节?
value string = "my_string";
[Byte*] bytes = string.______;
【问题讨论】:
如何将 Ceylon 中的字符串编码为 UTF-8 字节?
value string = "my_string";
[Byte*] bytes = string.______;
【问题讨论】:
import ceylon.buffer.charset {
utf8
}
shared void run() {
value string = "my_string";
List<Byte> bytes = utf8.encode(string);
Byte[] bytesSequence = bytes.sequence(); // in case a List isn’t enough
}
【讨论】:
encode 返回List<Byte> 而不是Byte[]?我认为List 用于可能可变的事物。
List 接口根本没有说明可变性。 List 可能是可变的或不可变的。 OTOH,我不太清楚为什么encode() 不只是返回一个惰性流,即{Byte*}。