I'm getting an error while trying to assign a environment variable value to a lateinit
variable.
The error is "'lateinit' modifier is not allowed on properties of primitive types".
My application.properties (reading the environment variable)
my.property.from.properties.file=true
MyService class:
@Component
class MyService @Autowired constructor(
private val someService: SomeService) {
@Value("\${my.property.from.properties.file}")
private lateinit var myBooleanEnabled: Boolean
Assigning a value to it does not solve the problem. For example, with
private lateinit var myBooleanEnabled: Boolean = true
I get 2 errors:
- 'lateinit' modifier is not allowed on properties of primitive types
- 'lateinit' modifier is not allowed on properties with initializer
For what I read, I need a Delegated (https://kotlinlang.org/docs/reference/delegated-properties.html) but I could not grasp it fully. Also, I don't want to have to write another method to set the property if there is a "cleaner" solution. Any ideas?