How does one mark a var in Kotlin volatile?
volatile public var tmpEndedAt: Long? = null
Is giving me the error: "unresolved reference: volatile".
According to the Kotlin documentation Kotlin-@Volatile. Marks the JVM backing field of the annotated property as volatile, meaning that writes to this field are immediately made visible to other threads. So, in Kotlin you can mark the property as volatile with @Volatile annotation.
The volatile keyword is intended to prevent the compiler from applying any optimizations on objects that can change in ways that cannot be determined by the compiler. Objects declared as volatile are omitted from optimization because their values can be changed by code outside the scope of current code at any time.
Marks the JVM method generated from the annotated function as synchronized , meaning that the method will be protected from concurrent execution by multiple threads by the monitor of the instance (or, for static methods, the class) on which the method is defined.
I decided to give Kotlin a shot by just using the "convert java to kotlin" function in IntelliJ. Apparently that set things up wrong.
I tried doing the same thing, but after applying the Kotlin Gradle plugin and placing the file in src/kotlin
and it all worked. Thanks for the help anyway guys.
The code would be:
@Volatile var tmpEndedAt: Long? = null
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With