florent
11/16/2018, 7:59 AMgildor
11/16/2018, 8:04 AMvar
properties, runtime will not allow to change it.
It required to safely pass data between threadsyuya_horita
11/16/2018, 8:04 AMflorent
11/16/2018, 8:05 AMgildor
11/16/2018, 8:05 AMgildor
11/16/2018, 8:05 AMflorent
11/16/2018, 8:06 AMgildor
11/16/2018, 8:06 AMflorent
11/16/2018, 8:06 AMflorent
11/16/2018, 8:06 AMgildor
11/16/2018, 8:06 AMgildor
11/16/2018, 8:06 AMgildor
11/16/2018, 8:07 AMgildor
11/16/2018, 8:07 AMyuya_horita
11/16/2018, 8:09 AMsome class withIn addition, some class withproperties, runtime will not allow to change it.var
val
properties are not allowed to be accessed by several threads either without being frozen.gildor
11/16/2018, 8:10 AMgildor
11/16/2018, 8:10 AMyuya_horita
11/16/2018, 8:11 AMflorent
11/16/2018, 8:12 AMlet
to be mutable ?florent
11/16/2018, 8:13 AMvar myMap = mutableMap<String, String>()
, in kotlin native, it will be frozen ?gildor
11/16/2018, 8:13 AMflorent
11/16/2018, 8:13 AMgildor
11/16/2018, 8:14 AMflorent
11/16/2018, 8:14 AMgildor
11/16/2018, 8:16 AMfun main(args: Array<String>) {
val myMap = mutableMapOf<String, String>()
println(myMap) // {}
myMap["foo"] = "bar"
println(myMap) // {foo=bar}
}
florent
11/16/2018, 8:16 AMflorent
11/16/2018, 8:17 AMflorent
11/16/2018, 8:17 AMflorent
11/16/2018, 8:17 AMflorent
11/16/2018, 8:18 AMgildor
11/16/2018, 8:18 AMflorent
11/16/2018, 8:18 AM@Suppress("UNCHECKED_CAST")
fun <T> addObserver(observer: Any, key: String, block: (T) -> Unit) {
val function: ((Any) -> Unit)? = block as? (Any) -> Unit
function?.let {
if(keyObservers.containsKey(key)){
keyObservers[key]?.add(observer, function)
} else {
val keyObserver = KeyObservers<Any>()
keyObserver.add(observer, function)
keyObservers[key] = keyObserver
}
}
}
florent
11/16/2018, 8:18 AMflorent
11/16/2018, 8:18 AMprivate val keyObservers = mutableMapOf<String, KeyObservers<Any>>()
gildor
11/16/2018, 8:18 AMgildor
11/16/2018, 8:18 AMgildor
11/16/2018, 8:18 AMgildor
11/16/2018, 8:18 AMflorent
11/16/2018, 8:19 AMgildor
11/16/2018, 8:19 AMflorent
11/16/2018, 8:19 AMgildor
11/16/2018, 8:19 AMflorent
11/16/2018, 8:19 AMflorent
11/16/2018, 8:19 AMgildor
11/16/2018, 8:19 AMgildor
11/16/2018, 8:19 AMgildor
11/16/2018, 8:19 AMgildor
11/16/2018, 8:20 AMgildor
11/16/2018, 8:20 AMflorent
11/16/2018, 8:21 AM@kotlin.native.ThreadLocal
?louiscad
11/16/2018, 8:21 AMflorent
11/16/2018, 8:23 AMgildor
11/16/2018, 8:25 AMgildor
11/16/2018, 8:25 AM@kotlin.native.ThreadLocal
as platform optional annotationgildor
11/16/2018, 8:26 AMflorent
11/16/2018, 8:26 AMJurriaan Mous
11/16/2018, 9:15 AM