Android/Kotlin
const val과 그냥 val의 차이
lipnus
2019. 1. 22. 14:56
반응형
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
반응형