Lateinit: enemy of your code cover | By Android Dev Nexus
Learn Android development
Repend when you want to use lateinit. There may be better options
Kotlin lateinit The modifier is a practical way to initialize non -null properties without requiring immediate assignment. However, when used with negligence, lateinit Can become a silent enemy for your code cover and test reliability. In this article, we will explore why lateinit Can harm the coverage of the code, how it affects unit tests and what alternatives you can use to avoid the traps.
Kotlin presented lateinit var To postpone the initialization of properties, which is particularly useful when injection of dependence, Android View links or test configurations.
class MyClass {
lateinit var dependency: Dependencyfun initialize(dep: Dependency) {
dependency = dep
}
fun doSomething() {
dependency.execute()
}
}
At first glance, lateinit This seems to be a useful tool, but it comes with hidden costs.
Grpahic Designer
Berita Olahraga
Lowongan Kerja
Berita Terkini
Berita Terbaru
Berita Teknologi
Seputar Teknologi
Drakor Terbaru
Resep Masakan
Pendidikan
Berita Terbaru
Berita Terbaru
Berita Terbaru