Hello, World! I'm having trouble finding the corre...
# multiplatform
b
Hello, World! I'm having trouble finding the correct syntax to declare an
expect
class and reflecting the constructors of the
actual
one. Here's what I'm trying to do: common:
Copy code
expect class File(path: String) {
    constructor(path: File, name: String)

    fun isDirectory(): Boolean
}
jvm:
Copy code
actual class File actual constructor(path: String): java.io.File(path) {
    actual constructor(path: File, name: String)
}
This results in
Primary constructor call expected
s
in kotlin you have to call primary constructor in your secondary for jvm, secondary constructor is not calling primary, resulting in an error
k
^
b
but the secondary constructor exists in JVM, what's the proper syntax to just "export" it?
s
but it does not exist in Kotlin
k
Could you cange the primary to a secondary?
s
I doubt that this way you will store semantics
Copy code
path: File, name: String
may not be equal to
path.absolutePath + File.SEPARATOR + name
tbh I would look on
Copy code
companion object {
    operator fun invoke(path: String)
    operator fun invoke(path: File, name: String)
}
but I don’t know if it is possible to have
expect/actual companion object
b
should I just do a wrapper
s
you can just copy logic of
<http://java.io|java.io>.File
constructor
b
this seems to work
Copy code
expect class File {
    constructor(path: String)
    constructor(path: File, name: String)

    fun isDirectory(): Boolean
}
Copy code
actual class File : java.io.File {
    actual constructor(path: String):super(path)
    actual constructor(path: File, name: String):super(path, name)
}
wait I think all I wanted was:
actual typealias File = <http://java.io|java.io>.File
😂
😅 2
sorry for the noise/confusion
d
Primary constructor is not mandatory.