4 ms·
> I'm curious, where have you found the need for lateinit? It's useful as soon as a field is managed by a container, which means it will most likely not be ini
by hota_mazi 10y ago
> I'm curious, where have you found the need for lateinit?
It's useful as soon as a field is managed by a container, which means it will most likely not be initialized at construction time of the object.
Examples of containers: Android, JavaEE, web servlet containers, DI frameworks, etc...
So basically, they are pretty much ubiquitous.
- snuxoll 10y ago> Android, JavaEE, web servlet containers, DI frameworks, etc... Most of which support constructor injection.
- hota_mazi 10y agoEr... none of them except maybe Guice? They all require a parameterless constructor so they can instantiate your objects before reflecting them.
- mejari 10y agoExactly. I spent some time testing out converting a small part of our large codebase that uses Spring to Kotlin and was able to easily switch over to constructor injection. I think it actually made the injection cleaner. It was nicer for my tests too, instead of @Mock/@InjectMocks magic.