First-class functions
In computer science, first-class describes programming language entities that can be declared and used anywhere. For instance, a class with the public modifier is a first-class citizen in Java.
In Kotlin, you don't need to create a class to declare a function; you can just do it in the file. In the preceding sample, the main function is a top-level function that's just declared in the Main.kt file. It can be used as the starting point for a program because first-class functions compile to the same bytecode as public final static functions in Java. To ensure this, go to Tools in IntelliJ IDEA and the following dialog window will open:
Go to the Kotlin submenu and click Show Kotlin Bytecode in the following context menu: ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access