Daniel Pitts
12/04/2024, 8:31 PM@JvmInline
value class Namespace(val uri: String) {
}
open class WithNamespace(val namespace: Namespace) {
constructor(url: String) : this(Namespace(url))
}
Spoiler: What type is Namespace on the JVM?Youssef Shoaib [MOD]
12/04/2024, 8:36 PMDaniel Pitts
12/04/2024, 8:37 PMYoussef Shoaib [MOD]
12/04/2024, 8:42 PMfun WithNamespace(url: String) = WithNamespace(Namespace(url))
Daniel Pitts
12/04/2024, 8:43 PMdata object CalDav : WithNamespace("urn:ietf:params:xml:ns:caldav") {...}
Daniel Pitts
12/04/2024, 8:45 PMYoussef Shoaib [MOD]
12/04/2024, 8:46 PMconstructor(url: String, unit: Unit = Unit) : this(Namespace(url))
Daniel Pitts
12/04/2024, 8:46 PMinterface Namespaced {
val namespace: Namespace
}
@JvmInline
value class Namespace(val uri: String) : Namespaced {
override val namespace: Namespace get() = this
fun name(name: String) = Name(name, this)
}
data object CalDav : Namespaced by Namespace("urn:ietf:params:xml:ns:caldav") {
Daniel Pitts
12/04/2024, 8:47 PMunit: Unit
. I think this is better though.Youssef Shoaib [MOD]
12/04/2024, 8:59 PMopen class WithNamespace(val namespace: Namespace, val unit: Unit = Unit) {
constructor(url: String) : this(Namespace(url))
}
Both constructors are accessible in Kotlin. The main constructor is (probably) marked synthetic or something, and the secondary constructor is accessible from Java.ephemient
12/05/2024, 12:52 AMKlitos Kyriacou
12/05/2024, 9:58 AMString
when you should be passing a Namespace
. Why do you want to circumvent this by introducing a wrapper function/constructor?Daniel Pitts
12/05/2024, 2:38 PM