Norbi
01/30/2024, 4:37 PMclass A<Any>(val a: Any)
fun <T: Comparable<T>> A(a: T): A<T> =
A(a) // <--- how to call the constructor of class A instead of calling function A() recursively?
Is this the most correct solution?
fun <T: Comparable<T>> A(a: T): A<T> =
A<Any>(a) as A<T>
Thanks.
EDIT: it is a theoretical question, just to know the edge cases of the language ;)Adam S
01/30/2024, 7:31 PMdata class A<Any>(val a: Any)
typealias AConstructor<T> = A<T>
fun <T: Comparable<T>> A(a: T): A<T> =
AConstructor(a)
fun main() {
println(A("x"))
println(AConstructor(1))
}
Klitos Kyriacou
01/31/2024, 9:12 AMclass A<Any>(val a: Any)
, the word Any
doesn't refer to the well-known type Any
? It is just a generic parameter. To avoid confusion, name it something like T
instead.Norbi
01/31/2024, 9:19 AMclass A<T: Any>(val a: T)
Sorry for the confusion...