Quantcast
Channel: Recent Questions - Stack Overflow
Viewing all articles
Browse latest Browse all 12111

Declare val without initialization in function

$
0
0
class Solution {     val message: String  //error : val must be initialized or abstract    message = "love" //error : val cannot be reassigned}

I understand what's happening in here - val cannot be reassigned.
So when I need val but can not initialize it i used to use by lazy

class Solution {    fun love(){        val message : String        message = "love"   //this works        message = "hate"   //this is error "val cannot be reassigned"    }}

Here I can delcare val without initialization and later write codemessage = "love".what's happening here?


Viewing all articles
Browse latest Browse all 12111

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>