请帮我看看怎么重构这两个函数,我对泛型不是很了解

天蓝dylan 2013-03-18 04:49:23
看着很不顺眼,函数里面的代码是一样的,能不能整合成一个方法?既可以判断Map的大小也可以判断Collection

	public static <T extends Collection<?>> boolean isNormalData(
Context context, T data) {
if (data == null) {
DUIUtil.ToastText(context,
context.getString(R.string.tip_data_null));
return false;
} else if (data.isEmpty()) {
DUIUtil.ToastText(context,
context.getString(R.string.tip_data_empty));
return false;
}
return true;
}

public static <T extends Map<?, ?>> boolean isNormalMapData(
Context context, T data) {
if (data == null) {
DUIUtil.ToastText(context,
context.getString(R.string.tip_data_null));
return false;
} else if (data.isEmpty()) {
DUIUtil.ToastText(context,
context.getString(R.string.tip_data_empty));
return false;
}
return true;
}

...全文
131 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
天蓝dylan 2013-03-19
  • 打赏
  • 举报
回复
引用 2 楼 ehzil 的回复:
public static <T extends Collection<?> & Map<?, ?>> boolean isNormalData(
试了一下不行啊,我用HashMap<String, String> data;会报错 Bound mismatch: The generic method isNormalData(Context, T) of type TogetherHelper is not applicable for the arguments (Context, HashMap<String,String>). The inferred type HashMap<String,String> is not a valid substitute for the bounded parameter <T extends Collection<?> & Map<?,?>>
失落的code 2013-03-19
  • 打赏
  • 举报
回复
public static <T extends Collection<?> & Map<?, ?>> boolean isNormalData(
天蓝dylan 2013-03-18
  • 打赏
  • 举报
回复
顶一下,求大神帮忙

80,351

社区成员

发帖
与我相关
我的任务
社区描述
移动平台 Android
androidandroid-studioandroidx 技术论坛(原bbs)
社区管理员
  • Android
  • yechaoa
  • 失落夏天
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧