简体   繁体   English

Kotlin Back-Tick在方法名称中转义:它是如何工作的?

[英]Kotlin Back-Tick escaping in method names: How does it work?

In Kotlin, it's possible to name a method using back-ticks like this: 在Kotlin中,可以使用这样的反向标记命名方法:

fun `i am a test method`(){
   Assert.assertEquals("x", "x")
}

The compiler generates a method with underscores instead of blanks: "i_am_a_test_method", which seems reasonable as the JVM does not permit methods with blanks afaik. 编译器生成一个带下划线而不是空白的方法:“i_am_a_test_method”,这似乎是合理的,因为JVM 不允许带有空白的方法。 How can Junit and/or Gradle report these tests with the back-ticked name though? Junit和/或Gradle如何使用反向标记的名称报告这些测试?

In a Java method descriptor , several characters have a special meaning, namely [ ( ) / and ; Java方法描述符中 ,有几个字符具有特殊含义,即[ ( ) /; . The space doesn't have any special meaning, and therefore it can be used directly in a method name; 该空间没有任何特殊含义,因此可以直接在方法名称中使用; that's exactly what the compiler does. 这正是编译器所做的。 The spaces are not converted to underscores. 空格不会转换为下划线。

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

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