Thursday, September 12, 2013

Can I create a member variable that is a type parameter of a generic?

Can I create a member variable that is a type parameter of a generic?

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?

No comments:

Post a Comment