...

Mobile App Development - Kotlin

Back to Course

Lesson Description


Lession - #390 Kotlin Data Types


How would I know my Kotlin data type?

In Kotlin, we can check the type of specific variable utilizing the is operator at runtime. It is an approach to checking the type of a variable at runtime to separate the flow for various objects.

What is Lateinit in Kotlin?
Lateinit is allowed for non-primitive data types only and the variable can't be of null type.

Kotlin Android. It is a very common use case where we want to return two values from a method, can be either of same data type or can be of different data types.




Let's see an example





fun main(>
{ val n=9; //int println(n>
; var f=2.89; //float println(f>
; var t="text"; println(t>
; var i=768567865789756899;//long println(i>
; }



Output



Try it here

Kotlin array Arrays are used to store multiple values in a single variable, instead of creating separate variables for each value. To create an array, use the arrayOf(>
function, and place the values in a comma-separated list inside it:
val cars = arrayOf("Volvo", "BMW", "Ford", "Mazda">


Kotlin data classes
It is to be expected to make classes whose fundamental intention is to hold information. In such classes, some standard usefulness and a few utility capacities are frequently precisely resultant from the information. In Kotlin, these are called information classes and are set apart with information:
information class User(val name: String, val age: Int>


Kotlin enum Identifications in Kotlin are information types that hold a bunch of constants. Enums are characterized by adding the modifier enum before a class as displayed beneath. Indeed, in Kotlin, Enums are classes.
enum class Months{
    January,
    February,
    March
}


Kotlin interview questions: