반응형
const val과 그냥 val의 차이
const
s are compile time constants. Meaning that their value has to be assigned during compile time,
unlike val
s, where it can be done at runtime.
This means, that const
s can never be assigned to a function or any class constructor, but only to a String
or primitive.
For example:
const val foo = complexFunctionCall() //Not okay
val fooVal = complexFunctionCall() //Okay
const val bar = "Hello world" //Also okay
https://stackoverflow.com/questions/37595936/what-is-the-difference-between-const-and-val
반응형
'Android > Kotlin' 카테고리의 다른 글
First-class citizen (1급객체) (0) | 2019.02.01 |
---|---|
Higher-order-function(고차함수) (0) | 2019.02.01 |
lateinit & by lazy (0) | 2018.12.11 |
let, run, apply, with (0) | 2018.12.11 |
클로저(Closure) (0) | 2018.12.09 |