我已经浏览了https://kotlinlang.org/docs/reference但我找不到在Kotlin中使用的保留关键字.Kotlin有多少个关键词?只要我们知道Java有自己的关键字列表,就像这里:
有语法参考https://kotlinlang.org/docs/reference/grammar.html
因此,双引号中的任何内容都是关键字(如"class")或运算符(如"%")。然而,许多关键字是“软”的(例如"file"),这意味着它们取决于它们的语法位置,并且仍然可以用作函数名称等。
根据@ hotkey的回答,Beta4 的硬关键字列表是:
"package",
"as",
"typealias",
"class",
"this",
"super",
"val",
"var",
"fun",
"for",
"null",
"true",
"false",
"is",
"in",
"throw",
"return",
"break",
"continue",
"object",
"if",
"try",
"else",
"while",
"do",
"when",
"interface",
"yield",
"typeof",
Run Code Online (Sandbox Code Playgroud)