I'm experimenting with the Java module system. I'm trying to use the ServiceLoader for generic interfaces. It works but I've got warnings in the module-info. Here is my minimal code
module testProvideWith {
provides ServiceGeneric with SString;
uses ServiceGeneric;
}
public interface ServiceGeneric<T> {
T getT();
}
public class SString implements ServiceGeneric<String>{
public String getT() {return "Hello";}
}
I'm not surprised to get a warning when I try
ServiceGeneric<String> serv=ServiceLoader.load(ServiceGeneric.class).findFirst().get();
I know about generic erasure, I understand that I would have to use annotations or some other trick to annotate the correct service. But... there is no mention at all of generic services that I can find. I expected to be able to write something like
module testProvideWith {
provides ServiceGeneric<String> with SString;
uses ServiceGeneric<String>;
//more cases could be added
}
...
ServiceLoader.load(ServiceGeneric.class,String.class)
where the module and the loader cooperate to keep track of what generic version is available.. but... nothing... no trace of anyone ever considering this possibility... I'm I missing something?