jeggy
09/12/2022, 3:05 PMinterface Criteria<T: Criteria<T>> { fun test(): T }
open class Filter1(val data: String = ""): Criteria<Filter1> {
override fun test() = Filter1("Basic")
}
object Standard: Filter1() {}
// How can I provide some correct type here?
fun whatever(): Criteria<*> {
// Some custom code...
return Standard
}
fun main() {
println(whatever().data)
}
Could someone help me with my whatever function here, so it returns the correct type? (playground: https://pl.kotl.in/z4lPq_kWE)Adam Cooper
09/12/2022, 3:09 PMinterface Criteria<T: Criteria<T>>
Is that intentional?jeggy
09/12/2022, 3:17 PMAdam Cooper
09/12/2022, 3:20 PMjeggy
09/12/2022, 3:22 PMFilter1 type.Youssef Shoaib [MOD]
09/12/2022, 4:19 PMfun whatever(): Criteria<Filter1>
However, you still won't be able to do .data though. That's because a Criteria<Filter1> is not guaranteed to be of type Filter1
You could instead just do:
fun whatever(): Filter1jeggy
09/12/2022, 5:37 PMCriteria . So it's important that it's not only supporting the Filter1 .Youssef Shoaib [MOD]
09/12/2022, 5:41 PMwhatever meant to decide what its return type is though? As in, you can't access .data on an arbitrary Criteria<*>. Is whatever meant to have a type parameter then?jeggy
09/12/2022, 6:13 PMRepository<Criteria<*>> , but I can't get this part to work.Youssef Shoaib [MOD]
09/12/2022, 6:16 PM.data? Because if so there is kind of a solution