In Scala code, I have
val pendingServices = new ConcurrentHashMap[String, JMap[Class[_ <: Service], Service]]()
From the caller side, Java, using looks like
Service$.MODULE$.pendingServices().get("key").put(Foo.class, new Foo());
Also I am able to get instance of some Service class by
Service$.MODULE$.pendingServices().get("key").get(Foo.class)
or from Scala,
Service.pendingServices.get("key").get(classOf[Foo])
The problem: it is possible to put unrelated Servicees in the map, like
Service$.MODULE$.pendingServices().get("key").put(Bar.class, new Foo());
if Foo and Bar both extends Service. So, how can I restrict Class[_ <: Service and Service from the definition to share same Service ?
I want to demonstrate my coworkers some cases when Scala's type system really helps. Tried with type lambdas, but my type-fu is not strong enought.