• Latest Code...

    Featured Post

    Implementing Hilt in a Kotlin Android Jetpack Compose Project with MVVM Architecture

     In modern Android development, maintaining a scalable codebase can be challenging, especially when it comes to dependency management. Hilt,...

    Val and Var in Kotlin


    Variables defined with var are mutable(Read and Write)
    Variables defined with val are immutable(Read only)

    Simply, var (mutable) and val (immutable values like in Java (final modifier)

    var x:Int=3
    x *= x
    
    //gives compilation error (val cannot be re-assigned)
    val y: Int = 6
    y*=y
    
    
    val and var both are used to declare a variable. 
    
    
    
    
    var is like general variable and its known as a mutable variable in  
    kotlin and can be assigned multiple times.   
     
    val is like constant variable and its known as immutable in 
    kotlin and can be initialized only single time.

    Contact Form

    Name

    Email *

    Message *