gpt4 book ai didi

kotlin - 在反引号内转义双引号

转载 作者:行者123 更新时间:2023-12-02 13:20:30 24 4
gpt4 key购买 nike

有没有办法像这样在方法名称中使用双引号?

@Test
fun `should do "something"`() {
// ...
}

它适用于 ',但不适用于 "。有没有一种方法可以转义双引号?

(由于语法错误,我收到了编译错误)

最佳答案

如果使用反引号进行转义,则可以在方法名称中使用特殊字符。
您的示例在我的Kotlin项目中编译。
但这也取决于目标平台,如果编译为Android,则字符集的限制更大。

在此处查看讨论-https://discuss.kotlinlang.org/t/more-characters-allowed-for-identifiers-than-grammar-specifies-what-is-supported/2359/11

这里的语法定义-https://kotlinlang.org/docs/reference/grammar.html#Identifier

关于kotlin - 在反引号内转义双引号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57408600/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com