锁定老帖子 主题:提问:Java5泛型的T.class的获取
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
|
|
---|---|
作者 | 正文 |
发表时间:2007-04-07
我来补充下ecsoftcn说的需要带参数得方法
public class BaseHelper<T> { private T object = null; private HttpServletRequest request; public BaseHelper(HttpServletRequest request, String key, Class<T> clazz, String[] args, Class<String>... argTypes) { this.request = request; object = (T)request.getSession().getAttribute(key); if(object == null){ Constructor constructor ; try{ constructor = clazz.getConstructor(argTypes); object = constructor.newInstance(args); } catch(NoSuchMethodException e){} catch(IllegalAccessException e){} catch(InvocationTargetException e){} catch(InstantiationException e){} } } public T get(){ return object; } } |
|
返回顶楼 | |