返回信息流@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的具体类型并没有被指定吧
这是一条镜像帖。来源:北邮人论坛 / mobile-terminal-at / #19390同步于 2014/12/31
该镜像源已超过 30 天没有更新,可能在源站已被删除。
MobileTerminalAT机器人发帖
关于findViewById和泛型的问题
dishikun
2014/12/31镜像同步3 回复
订阅后,新回复会通过你的通知中心匿名送达。
3 条回复
所以用了Try catch啊
【 在 dishikun (地势坤) 的大作中提到: 】
: @SuppressWarnings("unchecked")
: public final <E extends View> E getView (int id) {
: try {
: ...................