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

John Dior

09/19/2023, 4:50 AM
Ok question for design with KMP I have 2 libraries, libvader and libmaul Both libvader and libmaul implement the Sith class The Sith class is practically identical in each lib. Libvader and libmaul are for 2 different platforms I want to access the Sith class in common code. What do i do?
🌠 2
j

Jeff Lockhart

09/19/2023, 5:01 AM
Depending on your requirements, either define an
expect class Sith
or
interface Sith
wrapper API. Then implement the
Sith
class as an
actual class
or
class
implementing your
interface
in the two separate platforms, utilizing libvader and libmaul. If you go the
interface
route, you'd inject the platform implementation at runtime.
j

John Dior

09/19/2023, 5:12 AM
Ok that makes sense, I was trying this and it did not work
Copy code
fun main() {

    val f = F("hi")
    val g = G("hello")
    val q: KProperty1<G, *> = F::p convert g
    val r = q.get(g)

}


infix fun <T> KProperty1<*,*>.convert(t: T) = this as KProperty1<T, *> 
data class F( val p : String)
data class G( val p : String)