Hi! I am using Mockk and I am trying to build a ge...
# announcements
k
Hi! I am using Mockk and I am trying to build a generalized interface. My code:
Copy code
interface Captor<T> {
  val captor: CapturingSlot<T>
}
Mockk's class deinition:
Copy code
class CapturingSlot<T : Any>()
Yet, I am getting Type argument is not within its bounds. Expected: Any. Found: T Can anyone point me in the right direction?
s
have you tried just bounding your Captor’s type parameter?
interface Captor<T : Any>
k
@Shawn Thanks! I am obviously missing smth but my goal was to have
CapturingSlot<T>
and just pass a type to an interface. Yet,
CapturingSlot<T>
gives me
Type argument is not within its bounds. Expected: Any. Found: T
and I am a bit confused because explicit types all work, e.g.
CapturingSlot<String>
or any other type is ok
s
It’s because by default
T
has a bound of
Any?
bounding it to
Any
disqualifies null types
k
I got it! Sorry for being slow. Thank you so much for your help, it works exactly as I wanted!
s
no worries! this is something about the type system that isn’t terribly obvious