In Kotlin, it's possible to name a method using back-ticks like this:
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. How can Junit and/or Gradle report these tests with the back-ticked name though?
In the Kotlin language, there is a means of specifying the name of a function in backticks – ` `. In this case, the function name can contain spaces or other non-standard characters. In the most general use, the declaration of such a function looks like this: fun `set_of_characters` (list_of_parameters):return_type { // ... }
This presents some issues with Java interop, and in order to get around this Kotlin lets you surround those words with backticks so they don’t cause the compiler to yell at you. For example, if you are in Kotlin and calling a Java method called is, you have to escape it like this:
These might be cases where Java methods are called from code in a Kotlin language file. An example of this use is the use of various Java reserved keywords that cannot be used as names for functions in the Kotlin language (for example, the is keyword); making the use of functions more clear with the help of whole sentences, taken in back quotes.
Kotlin provides a set of functions to execute a block of code in the context of a given object: let, run, with, apply, and also. For the guidance on choosing the right scope function for your case, refer to Scope Functions. When writing libraries, it's recommended to follow an additional set of rules to ensure API stability:
In a Java method descriptor, several characters have a special meaning, namely [
(
)
/
and ;
. 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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With