https://kotlinlang.org logo
#multiplatform
Title
# multiplatform
k

Kyle Wood

11/11/2023, 11:59 PM
If I have a common library which targets the
AutoCloseable
experimental stdlib API, is there a way to make it also work for JVM? I get a type mismatch error when trying to use a Java
AutoCloseable
with my library https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-auto-closeable/
j

Jeff Lockhart

11/12/2023, 12:08 AM
AutoCloseable
is an
expect class
in Kotlin common and its JVM
actual
is the Java implementation. If you're getting an error, it's likely a false positive in the IDE.
k

Kyle Wood

11/12/2023, 12:12 AM
Yup, you're right. It builds and the test executes fine, it's an IDE error
j

Jeff Lockhart

11/12/2023, 12:14 AM
I use
AutoCloseable
in my KMP library and in some cases it works as expected, while in other cases, I get this error in the IDE for the JVM actual class:
Actual class 'SomeClass' has no corresponding expected declaration
The following declaration is incompatible because some supertypes are missing in the actual declaration:
@OptIn public final expect class SomeClass : AutoCloseable defined in somepackage in file SomeClass.kt
It's odd because it's pretty much the same scenario as others that don't display an error in the IDE, an
expect class
that implements
AutoCloseable
.
k

Kyle Wood

11/12/2023, 12:15 AM
I'll open an issue on youtrack about it, hopefully my particular issue is simple enough to be fixed, I haven't run into that one yet though
j

Jeff Lockhart

11/12/2023, 12:16 AM
Great. I'll add my error to the issue. I haven't created one for this yet.
k

Kyle Wood

11/12/2023, 12:17 AM
Alright cool - I'll push up my reproduction example to a git repo and create the issue, I'll drop the link in here once I've done that
👍🏼 1
3 Views