https://kotlinlang.org logo
#android
Title
# android
m

muralimohan962

08/01/2018, 6:22 AM
How to write a static block in kotlin classes?
w

wcaokaze

08/01/2018, 6:23 AM
Why do you need it? 🤔
m

muralimohan962

08/01/2018, 6:25 AM
While loading class i would like some code to execute.
w

wcaokaze

08/01/2018, 6:27 AM
Kotlin doesn’t have it IMO. I use Java whenever some low-level operations are needed.
c

chi

08/01/2018, 6:49 AM
@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

wcaokaze

08/01/2018, 7:17 AM
@chi I rarely do it. My project contains 0.1% Java code for bitwise operations
c

chi

08/01/2018, 7:22 AM
Okay. But you can still do those bitwise operations well in Kotlin
w

wcaokaze

08/01/2018, 7:29 AM
Yep. But if they are the most part of a class, Kotlin is a bit unreadable. It almost never happens
r

rudolf.hladik

08/02/2018, 9:26 PM
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
19 Views