is there a possibility to use contracts for assuri...
# announcements
e
is there a possibility to use contracts for assuring the compiler a
val
interface field will be initialized exactly only once?
m
What is your usecase here?
val
interface properties act as getter methods in java, I'm not aware of any way to tell compiler it will always return the same value
e
I know I'll init
names
exactly just once
Copy code
interface Buf {
    companion object {
        val names: IntBuffer
    }
}
m
yeah, compiler will force you to do so. However, interfaces don't have fields, only fieldless properties and actual field initialization is left to implementing classes
☝️ 1
what benefit would you have from being able to pass this info to compiler?
e
the same benefit you have using `val`s instead of `var`s: compiler optimizations?. Atm I'm using
laterinit var
though
m
ok, one trick you can use here is overriding
val
property in interface with
var
property in class
if that's helpful
e
that interface is supposed to be used in an enum though
m
I'm not exactly sure what your issue here is, could you share some code snippet?
e
to be honest, I'm experiment, my goal is actually to have an enumerator class backed by and
IntBuffer