https://kotlinlang.org logo
Title
r

rootandy

04/25/2019, 8:19 PM
Hey, maybe somebody can help me: I try to create a property with a list of elements, where the element have to inherit from a specific class and has to implement a specific interface. I ended up in sth like this:
private val <T> buffer: List<T> where T : A, T : SomeInterface
Problem: this is not working since
T
is not used in "its receiver type" - can somebody help me with the correct syntax for my purpose?
s

Shawn

04/25/2019, 8:28 PM
you can’t really have call-site variance for vals
I’m not sure what you’re trying to do is possible in the first place
you may want a function instead, but I can’t say for sure
k

karelpeeters

04/25/2019, 8:33 PM
I think he wants an intersection type, not actual generics.
s

Shawn

04/25/2019, 8:34 PM
shame we can’t have
List<T | SomeInterface>
😕
k

karelpeeters

04/25/2019, 8:37 PM
More like
&
😒imple_smile:
r

rootandy

04/25/2019, 8:39 PM
no function is no option
s

Shawn

04/25/2019, 8:39 PM
@karelpeeters true
r

rootandy

04/25/2019, 8:40 PM
yes
private val buffer: List<A & SomeInterface>
would be another great option to show what I mean