given this: `public fun <T> myFun(vararg ar...
# getting-started
d
given this:
public fun <T> myFun(vararg arg: T) where T : MyClass, T : MyInterface
how can i create collection<T> (outside this function)? what i should achieve is:
val x: Set<T> = setOf(a, b)
or like
val x: Set<MyClass & MyInterface> = setOf(a, b)
if i remove the explicit type it works, but i need it for a function return type (type inference errors)
r
Intersection types are not denotable in Kotlin, even though they exist in the type system. Hopefully that will change someday.
s
like Ruckus said, your code basically works: https://pl.kotl.in/sce5crCw- But and-ing types with
&
, like in`Set<MyClass & MyInterface>`, doesn't exists. I was already surprised that I could double specify it for the generic function argument 😅
s
• open class A • interface C • val <T> T.value:Set<T> where TA,TC get()=setOf(this)