I have a class in a multiplaform project, and I want the JS implementation has only one private constructor:
expect class JsonConverter { fun stringify(o: Any?): String fun <T> parse(text: String): T } actual class JsonConverter private constructor() { companion object { val instance = JsonConverter() } actual fun stringify(o: Any?): String { return JSON.stringify(o) } actual fun <T> parse(text: String): T { return JSON.parse<T>(text) } }
However the compiler complains:
Actual class ‘JsonConverter’ has no corresponding expected declaration
unless I remove “private constructor ()” in the actual class.
Could anyone indicate how I can define an actual class with only one private constructor in a multiplatform project?