0

I have been using/learning Kotlin for a while now and I have only once seen ` being used.

System. `in`

I have tried finding something about this, but I was not able to.

halfer
  • 19,824
  • 17
  • 99
  • 186
Marcel
  • 1,509
  • 1
  • 17
  • 39

1 Answers1

7

It’s the syntax for escaping keywords like in. When a Java library uses one of these as an identifier (function/property name etc), it must be surrounded with backticks if called from Kotlin. Otherwise, the compiler tries to interpret it as a keyword which will make the code fail to compile.

Escaping for Java identifiers that are keywords in Kotlin

Some of the Kotlin keywords are valid identifiers in Java: in, object, is, etc. If a Java library uses a Kotlin keyword for a method, you can still call the method escaping it with the backtick (`) character:

foo.`is`(bar)

Here’s a list of keywords: https://kotlinlang.org/docs/reference/keyword-reference.html

Community
  • 1
  • 1
s1m0nw1
  • 76,759
  • 17
  • 167
  • 196
  • 2
    +1 - may be worth noting that it is not solely for escaping keywords, and there are still restrictions on identifiers surrounded with `, it is used to escape anything that would otherwise be an invalid identifier, such as anything starting with a digit or anything containing spaces - of course, these would not be accessible from Java code without causing a syntax error. – Salem Jan 08 '18 at 18:36