Use of backticks in Kotlin
``
Backticks in Kotlin have two properties:
- Can solve the problem of keyword conflicts
- Can force an illegal character to become legal
scenes to be used:
- Intermodulation with methods in Java:
public class JavaTest {
public static void is() {
System.out.println("这是一个java方法");
}
}
Here you can see that the method name in java is Is, but it is a keyword in Kotlin is
. So there will be compile errors.
But we can get around this with backticks:
fun main() {
JavaTest.`is`();
}
- If you have methods that need to be used in Kotlin modules, but you don't want to provide them to java. You can try naming illegal characters.
It works fine in Kotlin, but fails to compile in Java.