Marc
04/22/2025, 11:19 AMinternal expect class ConcurrentMutableMap<K, V>() : MutableMap<K, V>
iOS:
internal actual class ConcurrentMutableMap<K, V> : MutableMap<K, V> {
override fun put(key: K, value: V)...
}
Android/JVM:
internal actual class ConcurrentMutableMap<K, V>(
map: ConcurrentHashMap<K, V>
) : MutableMap<K, V> by map {
actual constructor() : this(ConcurrentHashMap())
}
This does not show any errors inside of IntelliJ, but when compiling with Gradle it fails with the following error:
commonMain/kotlin/PlatformApiProviders.kt:15:17 Class 'ConcurrentMutableMap' is not abstract and does not implement abstract member 'put'.
Just as a test, I tried manually adding the missing function inside of my common definition (as well as adding "actual" to the function definition in my iOS code):
internal expect class ConcurrentMutableMap<K, V>() : MutableMap<K, V> {
override fun put(key: K, value: V): V?
}
And this fixes the issue, but now it just complains that "remove" is not implemented instead. My question now is if there is a way to fix this issue without just listing every function defined in MutableMap
again in my common code.Alexandru Caraus
04/22/2025, 12:00 PMMarc
04/22/2025, 12:02 PMAlexandru Caraus
04/22/2025, 12:14 PMMichael Krussel
04/22/2025, 12:14 PMcommonMain
source set.
But a typealias might be better.
public actual typealias ConcurrentMutableMap = ConcurrentHashMap
Alexandru Caraus
04/22/2025, 12:15 PMAlexandru Caraus
04/22/2025, 12:15 PMMarc
04/22/2025, 12:15 PMMichael Krussel
04/22/2025, 12:17 PMconcurrentMutableMapOf
.Marc
04/22/2025, 12:17 PMMarc
04/22/2025, 12:20 PMMarc
04/22/2025, 12:27 PMinternal actual typealias ConcurrentMutableMap<K, V> = ConcurrentHashMap<K, V>
causes the following issue:
'actual typealias ConcurrentMutableMap<K, V> = ConcurrentHashMap<K, V>' has no corresponding members for expected class members:
expect val keys: MutableSet<K>
The following declaration is incompatible because return type is different:
val keys: ConcurrentHashMap.KeySetView<K!, V!>
Michael Krussel
04/22/2025, 12:29 PMexpect fun ConcurrentMutableMap<K, V>(): MutableMap<K, V>
would be a reasonable solution. I guess the main issue is that it means you cannot take a ConcurrentMutableMap
as an argument to enforce concurrency.
expect
classes are still considered experimental versus expect functions.Marc
04/22/2025, 12:31 PMput
being missing on top of the incompatible definition for keys
field.Marc
04/22/2025, 12:32 PMMarc
04/22/2025, 12:33 PMactual
to all of the implementations on iOS. Of course I am not crazy about using a fix like that...Marc
04/22/2025, 12:35 PM