Kotlin TutorialLesson 7Free preview
Kotlin Variables
This lesson is part of Kotlin · All levels
Summary
This lesson reviews the declaration of variables in Kotlin using the keywords 'val' and 'var'. Kotlin strongly advocated the concept of immutability, where the value that does not need to be changed should be declared with 'val'. Kotlin's type inference feature also automatically determines the type of variable data without having to be written manually.
Key points
- The keyword 'val' is used to declare the read-only (immutable) variable
- The keyword 'var' is used for variables whose values are reversible (mutable)
- Kotlin supports type inference so data type writing is often optional.
- Declaring a variable with 'val' is best practice for code stability
Full lesson
Code examples and quizzes
Full lessons, code examples, and quizzes are available to subscribers. 5 questions.