Kotlin's Type Inference
Understand Kotlin's powerful type inference capabilities and how to use them to write more succinct code.
We'll cover the following...
Type inference is a compiler feature that allows you to omit types in your code when the compiler can infer it for you.
Type Inference in Kotlin #
Kotlin’s compiler can infer the types of most variables, so adding the type is optional:
Press + to interact
// Run the code to see the variable's typesval string = "Educative"val int = 27val long = 42Lval double = 2.71828val float = 1.23fval bool = true
Note: The terms on the left-hand side of the equals sign are just the variable names, not the data types. ...
Create a free account to view this lesson.
By signing up, you agree to Educative's Terms of Service and Privacy Policy