One must consider the variables holding arraylist can add or remove values within the arraylist object, while still being declared as an immutable variable. var age: Int = 30 val name: String = "Africa" No fear of having unintended value changes somewhere in your project just declare your variable with val. It’s always recommended to start with val. But in kotlin we start declaring either with var (for mutable ones) and val (for immutable variables). In java to make variable immutable we uses final keyword. Will explain about the var variable few lines later It’s exotic but gets you compile time error. But in kotlin much emphasis is made on the actual variable not it’s type, additionally it has smart data type inference feature, java considers such attempt as “prohibidato”- I know it’s Spanish. In java we start with the data type then the variable name and we can or not initialize the variable. When declaring a variable flip data type to the other side int javaVar = 12 // data type comes first var age: Int = 30 // variable then datatype(optionally□) and no semicolon□
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |