Main navigation

Learning Kotlin: The awesome that is the backtick

Submitted by Robert MacLean
on Thu, 07/05/2018 - 09:00

More Information

This is the 14th post in a multipart series.
If you want to read more, see our series index

The backtick in Kotlin is meant to allow Kotlin to use keywords or, since Kotlin is meant to interop with Java, allow Kotlin to call Java functions that might conflict with Kotlin; for example, this won't work

valclass="school"

println(class)

If we wrap class in backticks (as it is a keyword) then it works just fine:

val `class` ="school"

println(`class`)

This is nice... however it can be used for function names too, for example with tests we might use underscores to make the name verbose: