Defining Variable in Kotlin

By | October 8, 2017

Two type of keyword is used to defile a variable in Kotlin . these are

  • val (immutable)
  • var (mutable)

immutable : That means  you can not change the value . Assign value only one time . Its similar constant variable in strongly type language line c#, JAVA . If you uncomment this line program show compile type error cause immutable variable can not change value

mutable : if you need a variable which value change frequently or sometimes need to create variable var keywork . Mutable means changeable type variable .

Note: Kotlin statement no need to end with semicolon , its the beauty if coding and very simple to write



Leave a Reply