Hey can somebody give me proper example why val may be not initialized at compile time (so we need to add
const
modifier) ?
a
agomez
06/13/2017, 11:45 PM
igor.wojda: where did you read that?
i
igor.wojda
06/14/2017, 12:06 AM
This is the main reason why
const
exist. isn't it? e.g. annotation processor must know argument value at compile time and val is not accepted
Copy code
val answer: Int = 42
const val MAX_LOG_ENTRIES = 100
@MyLogger(MAX_LOG_ENTRIES ) // OK
class Test {}
@MyLogger(answer) // error
class Test2 {}
annotation class MyLogger(val value: Int)
a
agomez
06/14/2017, 12:53 AM
val may not be initialized at compile time when referring a complex type
agomez
06/14/2017, 12:54 AM
val outStream = FileOutputStream("/tmp/foo")
agomez
06/14/2017, 12:55 AM
only String and primitives can be known at compile time