I tried to employ the code given in this answer. I did this:
public class ListClass<T> {
  private class ObjectFactory<T> {
    //This should the the class of generic type T which is what I need
    public final Class<T> cls;
    @SuppressWarnings ("unchecked")
    public ObjectFactory()
    {
      //This three lines are from the linked answer - I don't really understand them
      Type type = getClass().getGenericSuperclass();
      ParameterizedType paramType = (ParameterizedType) type; //java.lang.ClassCastException: java.lang.Class cannot be cast to java.lang.reflect.ParameterizedType
      cls = (Class<T>) paramType.getActualTypeArguments()[0]; 
    }
    public T createNew(... some parameters ...) {
      return (T)new Expression(cls, "new", new Object[]{... some parameters ...}).getValue();
    }
  }
  public final ObjectFactory<T> factory = new ObjectFactory<T>();
  public generateItem() {
    //let add() be method that adds item of type T to this list
    this.add(factory.createNew(... some parameters ...));
  }
}
What am I dong wrong?
 
     
     
    