loading...
Cover image for Type Inference in Kotlin. How things exactly work behind the scenes.

Type Inference in Kotlin. How things exactly work behind the scenes.

jay_tillu profile image Jay Tillu😎 ・1 min read

Type — Data Type
Inference — To automatically identify something.

  • kotlin is a strongly typed language that supports Type Inference.

  • Kotlin compiler can automatically identify the data type of the variable. The compiler knows this by the initializer.

  • So if you initialize the value on the declaration, you don’t need to define data type explicitly.

  • Because every primitive type has a default value. The compiler will directly assume the size and type to a variable by that.

  • For example, if you assign any whole number to a variable, the compiler will directly assume that the variable is of type Int.

  • But remember if you want to initialize the value to the variable later, then, in that case, you have to define the data type explicitly. In that case, the concept of type inference won’t work.

So, guys, that’s it for type inference. This is how all the magic works behind the scenes. Feel free to ask any questions.

Till then Keep Coding, Keep Loving.

Wanna get in touch with me? Here are links. I’ll love to become your friend. 😊
Twitter
Facebook
Instagram
Medium
or just mail me at jayviveki13@gmail.com

Posted on by:

jay_tillu profile

Jay Tillu😎

@jay_tillu

🌏 विधायास्य धमॅस्य संरक्षणम् 🌍 ☀️ Society before Self ☀️ 🙏🏻 Humanism by Religion 🙏🏻 💻 Work for Mankind 💻 🌐 Believes in वसुधैव कुटुम्बकम् 🌐

Discussion

pic
Editor guide