How to write a static block in kotlin classes?
# android
m
How to write a static block in kotlin classes?
w
Why do you need it? 🤔
m
While loading class i would like some code to execute.
w
Kotlin doesn’t have it IMO. I use Java whenever some low-level operations are needed.
c
@muralimohan962 companion objects with init blocks might seems like the closest to that. @wcaokaze can you provide examples of these low-level operations where one has to resort to writing Java?
w
@chi I rarely do it. My project contains 0.1% Java code for bitwise operations
c
Okay. But you can still do those bitwise operations well in Kotlin
w
Yep. But if they are the most part of a class, Kotlin is a bit unreadable. It almost never happens
r
Kotlin has companion objects, they are like static. with @JvmStatic annotation its same as static. Not sure about the correctnes of annotation name, but im sure you can google it