Introduction

This is what the declaration of listOf in Kotlin really looks like:

public fun <T> listOf(vararg elements: T) : List<T>

Let’s go through this step by step:

The public keyword is no surprise for Java professionals.

However, the second keyword, fun, lets even experienced Java users down because there is no fun in Java (well, at least not as much as in Kotlin!).

Kotlin’s fun keyword

Just like variable declarations initiated with their own keywords (var or val), functions are also declared with a specific keyword. Its name, fun, stands for function.

The return type is last

Create a free account to view this lesson.

By signing up, you agree to Educative's Terms of Service and Privacy Policy