Why does this Kotlin method have enclosing backticks?

前端 未结 5 1992
感情败类
感情败类 2020-11-27 06:16

What are the backticks used for in the snippet below?

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

verifier.`is`(amount         


        
5条回答
  •  旧巷少年郎
    2020-11-27 06:43

    The backtick are a "workaround" to allow you to call methods that have a name representing a Kotlin keyword.

    See kotlinlang:

    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

提交回复
热议问题