Kotlin的重音口音是什么意思?

mle*_*fer 2 kotlin

请尽可能多的表达/定义.

我正在编写一个测试函数,在调用失败后,函数返回:

`this `fails with` "the state is propagated"`
Run Code Online (Sandbox Code Playgroud)

(周围的严重口音失败了^我不知道如何逃避,对不起)

Mib*_*bac 10

当某些东西是Kotlin关键字(比如Java System.in)时你想要使用它们,但你需要调用它.那你可以做

System.`in` 
Run Code Online (Sandbox Code Playgroud)

而是让它工作.

您还可以在变量,函数,类和任何其他标识符中使用它.关于Kotlin文档的这个主题有一小段.


Nae*_*mul 7

事实上,它远不止于此。

您可以使用名称中包含空格或带重音符的符号的任何类、函数、变量或标识符

class `Class name with spaces` {
    fun `method name with spaces, +, -`(`a parameter`: Int) {
        val `variable?!` = `a parameter` + 1
        println(`variable?!`.toString())
    }
}

fun main(args: Array<String>) {
    val instance = `Class name with spaces`()
    instance.`method name with spaces, +, -`(100)
}
Run Code Online (Sandbox Code Playgroud)

这是一个可编译和工作的代码: 结果

这通常用于测试,以使测试方法名称不言自明。

class OperationsUnitTest {
    @Test
    fun `addition should be commutative`() {
        ...
    }
}
Run Code Online (Sandbox Code Playgroud)