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 multi-part series. If you want to read more, see our [series index](/learning-kotlin-introduction)

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

  1. val class = "school"
  2. println(class)

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

  1. val `class` = "school"
  2. 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:

  1. fun should_return_true_for_values_of_one() {


  1. fun `should return true for values of one`() {

Yes! That is a function name with REAL SPACES in it! AWESOME!