Open pgaschuetz opened 12 years ago
Sorry, here's a version that calls the correct constructor
@Override
@SuppressWarnings("unchecked")
public P createPresenter() {
ParameterizedType thisType = (ParameterizedType) getClass().getGenericSuperclass();
Class<V> viewClazz = (Class<V>) thisType.getActualTypeArguments()[0];
Class<P> presenterClazz = (Class<P>) thisType.getActualTypeArguments()[1];
try {
Constructor<?> ctor = presenterClazz.getConstructor(viewClazz);
return (P) ctor.newInstance(this);
} catch (NoSuchMethodException e) {
throw new UnsupportedOperationException(
"No default constructor for Presenter " + presenterClazz.getSimpleName() + " available.");
}
catch (Exception e) {
throw new RuntimeException(e);
}
}
Hi,
here's a replacement for AbstractView.createPresenter(), which uses reflection to determine and create the Presenter