What is the difference between “const” and “val”?

前端 未结 7 2106
既然无缘
既然无缘 2020-12-22 17:20

I have recently read about the const keyword, and I\'m so confused! I can\'t find any difference between const and the val keyword, I

7条回答
  •  春和景丽
    2020-12-22 18:01

    Both val and const are immutable.

    const is used to declare compile-time constants, whereas val for run-time constants.

    const val VENDOR_NAME = "Kifayat Pashteen"  // Assignment done at compile-time
    
    val PICon = getIP()  // Assignment done at run-time
    

提交回复
热议问题