In order to create a variable, the compiler needs to know three things:
1. What the variable’s name is.
2. Whether or not the variable can be reused.
3. What type of variable it is.
Use var to define a variable whose value may change.
Use val to define a value whose value will stay the same.
Kotlin's ability to infer the type is called type inference.
Explicitly declare a variable’s type:
var x: Int = 3
The Kotlin compiler will only let you assign a value to a variable if the value and variable are compatible. If the value is too large or it’s the wrong type, the code won’t compile.
Every numeric type has the following conversion functions: toByte(), toShort(), toInt(), toLong(), toFloat() and toDouble().
In Array, Declaring a variable using val means that you can’t reuse the variable for another object. You can, however, still update the object itself.
Guide to watch:
00:00 Introduction
01:20 How to create file with extension in IntelliJ idea?
02:55 Kotlin Variables Complete Tutorial
19:45 How Explicitly declare a variable’s type?
21:45 How to covert variable data type in Kotlin using conversion functions?
26:47 How to define a array variable in Kotlin?
28:52 Const variable in Kotlin
31:20 Revision of Variables
#KotlinVariable #variables #KotlinDataType #Kotlin #KotlinBasics #CompleteCourse #tutorial #KotlinTutorial #HindiTutorial #KotlinHindi #KotlinHindiTutorial #KotlinCompleteTutorial #KotlinForAndroid
Disclaimer- Some content are used for educational purposes under fair use.
Copyright Disclaimer Under Section 107 of the Copyright Act 1976, allowance is made for "fair use" for purposes such as criticism, comment, news reporting, teaching, scholarship, and research. Fair use is a use permitted by copyright statute that might otherwise be infringing. Non-profit, educational, or personal use tips the balance in favor of fair use. All credit for copyright material used in the video goes to the respected Owner.
Thank you guys.