vendredi 31 juillet 2015

Returning subclass instance from superclass

I have a Java class A in my SDK. I am now breaking it to two classes AParent, A without changing the APIs signature for the users. This is being done as the A class (which is now the wrapper class) would have functionality specific to the environment while AParent will have common APIs. The problem I am facing is that A initially had many methods (static and non static) returning or accepting instances of its subclass via generics. To give you an idea, these methods signature looked like this :
public static <T extends A> T create(Class<T> subclass)
public <T extends A> T fetch() throws AException
I would like to make these methods a part of the parent class, AParent but would like to change the method signature to change and instead return something like:
public static <T extends AParent> T create(Class<T> subclass)
public <T extends AParent> T fetch() throws AException
But to the end user the signature shall still be the same and he shouldn't be noticing this change in the APIs signature.

Aucun commentaire:

Enregistrer un commentaire