In Scala code, I have
val pendingServices = new ConcurrentHashMap[String, JMap[Class[_ <: Service], Service]]()
On the caller side, Java using looks like
Service$.MODULE$.pendingServices().get("key").put(Foo.class, new Foo());
I can also get an instance of some class Service
Service$.MODULE$.pendingServices().get("key").get(Foo.class)
or from Scala,
Service.pendingServices.get("key").get(classOf[Foo])
Problem: you can put unrelated Servicees on the map , for example
Service$.MODULE$.pendingServices().get("key").put(Bar.class, new Foo());
If Fooand Barare both expanding Service. So, how can I limit Class[_ <: Serviceand Servicefrom the definition to share the same Service?
I want to demonstrate to my employees some cases where a system like Scala really helps. Tried the lambdas type, but my fu type is not strong enough.
source
share