Types of Keywords

Many programmers are used to the notion that you cannot use keywords as the names of variables, properties, functions, and the like. So, for example, this fails to compile:

fun main() {
  val class = 1337  

  println(class)
}

But some keywords, like import, work just fine:

fun main() {
  val import = 1337  

  println(import)
}

There are a few types of keywords in Kotlin, and each has its rules for where and when you can use them as identifiers.

Hard Keywords

Hard keywords like class, cannot be used as identifiers anywhere. Most Kotlin keywords are considered to be hard.

The roster of hard keywords will vary by Kotlin version, but it includes things that you might expect beyond class, such as:


Prev Table of Contents Next

This book is licensed under the Creative Commons Attribution-ShareAlike 4.0 International license.