Learnerslesson
   JAVA   
  SPRING  
  SPRINGBOOT  
 HIBERNATE 
  HADOOP  
   HIVE   
   ALGORITHMS   
   PYTHON   
   GO   
   KOTLIN   
   C#   
   RUBY   
   C++   




KOTLIN - VAL


Say in your program you need some values that should never be changed. And this is where 'val' comes into picture.


Let us simplify with the below example.


Example :



fun main(){
	
    val x = 5
    x = 7
    println(x)
} 


Output :



 Val cannot be reassigned

So, in the above code we have created a constant 'x' using the 'val' keyword.


val x = 5

java_Collections

Once the value is assigned to 'x', it cannot be changed as it is a constant.


And that is the reason we ended up with the below error message.


Val cannot be reassigned