Search code examples
kotlinandroid-notifications

How to access Notification.when field in Kotlin?


How to access Android Notification object's Notification.when field in Kotlin?

when is a keyword in Kotlin so notify.when causes Syntax Error on Android Studio.

Reference


Solution

  • Use the back apostrophes.

    val notification = Notification()
    notification.`when`
    

    Link to documentation - https://kotlinlang.org/docs/java-interop.html#escaping-for-java-identifiers-that-are-keywords-in-kotlin