Why does this Kotlin method have enclosing backticks?

Viewed 14971

What are the backticks used for in the snippet below?

Why add them around the fun is(amount:Int ):Boolean { ... }?

verifier.`is`(amount)
6 Answers

Useful for tests

Backticks are very useful in tests for long function names:

@Test
fun `adding 3 and 4 should be equal to 7`() {
    assertEquals(calculator.add(3, 4), 7)
}

This makes the function names more readable. We can add spaces and other special characters in the function names. However, remember to use it only in tests, it's against the Kotlin coding conventions of the regular code.

Related