Hi. I'm implementing a toy ServiceLocator kind of thing.
Is it possible to achieve something akin to this via the type system?
Copy code
fun registerService(interface: ???, impl: ???) { ... }
registerService(UserInterface::class, UserService()) // ok
registerService(CarInterface::class, CarService()) // ok
registerService(ChairInterface::class, TableService()) // fail, because TableService does not implement ChairInterface
d
diesieben07
12/12/2018, 11:45 AM
fun <T : Any> registerService(interface: KClass<T>, impl: T)
a
arve
12/12/2018, 12:05 PM
👌, thanks!
arve
12/12/2018, 12:13 PM
Can I extend this constraint to my MutableMap serviceCache as well, I wonder.. 🤔 Or would I have to be content with Map<Any, Any>