I have a lot of proxy classes around services, and all look (almost) the same. Can I reduce code duplication somehow by using a generics singleton class, that takes the Service
and Port
class as type parameters?
This is my completely wrong code with what I want to get started:
public class MyProxy<S extends Service, P extends BindingProvider>
{
private static final MyProxy<S extends Service, P extends BindingProvider> instance
= new Proxy<S extends Service, P extends BindingProvider>();
private S service;
public static MyProxy<S extends Service, P extends BindingProvider> getInstance() {
return instance;
}
}
- The type parameters for
MyProxy
I assume to be correct. - Can I declare a static
instance
singleton member variable, and how? - The member variable
service
should be more easy, can I have a type parameter as a member, anyway? - How about the return type of
getInstance()
, how to I write it?
Here is an example for such a proxy skeleton with a single type parameter:
So you can use it the following way:
Assuming that A is a subclass/implementation of
Service