Dynamic Types

Way back in Chapter 2, we mentioned that Kotlin uses a static type checking system. This means that every variable, function parameter, return type, and expression in Kotlin has a type that is known at compile time. This information is either inferred by the compiler or declared explicitly in your Kotlin code.

The static type checking system allows the compiler to confirm that you are accessing behaviors that exist for the kind of data you are working with – a powerful ability. Many of IntelliJ’s code editing, analysis, and refactoring tools build on the static type system.

By contrast, JavaScript’s type system is dynamic. In a dynamic type system, types are validated at runtime instead of compile time. Also, JavaScript ...

Get Kotlin Programming: The Big Nerd Ranch Guide, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.