简体   繁体   English

如何在Kotlin中制作Null角色

[英]How do I make a Null character in Kotlin

In Java, one can use the escape sequence \\0 to represent the Null character 在Java中,可以使用转义序列\\0来表示Null字符

\\0 and \\0000 are not valid escape sequences in Kotlin, so I've been using a static java char and accessing that from Kotlin. \\0\\0000在Kotlin中不是有效的转义序列,所以我一直在使用静态java char并从Kotlin访问它。

public class StringUtils{
  public static char escapeChar = '\0';
}

Is there a Null character literal, or a better way of doing this in Kotlin? 在Kotlin中是否有一个Null字符文字或更好的方法?

These options will work: 这些选项将起作用:

  • '\' (Unicode escape syntax, as described in the docs ) '\' (Unicode转义语法,如文档中所述)
  • 0.toChar() ( conversions are optimized and have no function call overhead) 0.toChar()转换已优化且没有函数调用开销)
  • import java.lang.Character.MIN_VALUE as nullChar , then use nullChar ( renaming import ) import java.lang.Character.MIN_VALUE as nullChar ,然后使用nullChar重命名导入

I believe it must be '\' . 我相信一定是'\' Please visit this page for more information. 请访问此页面以获取更多信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM