转载自:http://zhidao.baidu.com/question/1637815200281856620.html?qbl=relate_question_0&word=baseAction
public T model ;
@SuppressWarnings("unchecked")
public BaseAction(){
try {
ParameterizedType type = (ParameterizedType) this.getClass().getGenericSuperclass();
Class<T> clazz = (Class<T>) type.getActualTypeArguments()[0];
model = clazz.newInstance();
} catch (Exception e) {
e.printStackTrace();
}
}
貌似是获取BaseAction的父类对象的一个实例,并赋值给BaseAction的属性model 。
本文介绍SSH框架中BaseAction<T>的实现原理及构造方法。通过泛型获取父类实例并初始化model属性。

857

被折叠的 条评论
为什么被折叠?



