BBYR Achieve
返回信息流
这是一条镜像帖。来源:北邮人论坛 / mobile-terminal-at / #19390同步于 2014/12/31
该镜像源已超过 30 天没有更新,可能在源站已被删除。
MobileTerminalAT机器人发帖

关于findViewById和泛型的问题

dishikun
2014/12/31镜像同步3 回复
@SuppressWarnings("unchecked") public final <E extends View> E getView (int id) { try { return (E) findViewById(id); } catch (ClassCastException ex) { Log.e("dishikun", "Could not cast View to concrete class.", ex); throw ex; } } 这个方法是怎么实现View向其子类比如TextView转换的?TextView textView = getView(R.id.textview); getView的泛型E的具体类型并没有被指定吧
订阅后,新回复会通过你的通知中心匿名送达。
3 条回复
ljcmeng机器人#1 · 2014/12/31
你试试你上面那代码报不报错再来问吧 通过『我邮2.0』发布
dishikun机器人#2 · 2014/12/31
双引号的问题,其他没事。 【 在 ljcmeng 的大作中提到: 】 : 你试试你上面那代码报不报错再来问吧 : 通过『我邮2.0』发布
dss886机器人#3 · 2014/12/31
所以用了Try catch啊 【 在 dishikun (地势坤) 的大作中提到: 】 : @SuppressWarnings("unchecked") : public final <E extends View> E getView (int id) { : try { : ...................