Hi folks, quick question. How come i can import ja...
# multiplatform
g
Hi folks, quick question. How come i can import java.util.UUID in commonMain? In commonMain:
Copy code
public expect class UUID
In jvmMain
Copy code
public actual typealias UUID = java.util.UUID
In another part in commonMain:
Copy code
import java.util.UUID

public data class Account(
    public val uuid: UUID,
    public val number: String,
    public val firstName: String,
    public val lastName: String,
    public val identityKey: String
)
g
You cannot and you should not. Have a look at https://github.com/hfhbd/kotlinx-uuid or https://github.com/benasher44/uuid
g
Actually i was trying to play with expect and actual
g
Oh ok, clearer after you edited the message. You don't want to import java.util; you want to import your
expect
UUID
g
Yup that's what i thought, thanks for the help. For some reason intelij did not import automatically my expect . So i just typed manual the import and it worked lol . Still pretty new to KMM 🙂
Another quick question is it ok to declare my actual impl with typealis as i did in jvmmain?
g
Yes it's totally fine. You have some constraints when using a typealias, the method needs to match the
expect
class, so if you support more than just jvm, you will probably need a mapping class instead of just a typealias at some point.
g
Really thanks for the info :)