I am trying to use generics to create an object that can be a type of T, is this possible?
public class SoapObjectToModel <T> {
public ArrayList<T> convert(SoapObject soapObject) {
ArrayList<T> result = new ArrayList<T>();
// Somehow initialize an object of type T
}
}
You cannot create an object of type
T.Always remember you could always have
SoapObjectToModel<MyAbstractClass>, and what will happen if you try to createT? Will it create an abstract class?As a workaround, you might want to pass an element of type
Tas a parameter, and use reflection to create a new object, or even better – have a look at the Factory Design Pattern