且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

ArrayList 是原始类型.对泛型类型 ArrayList 的引用应该参数化

更新时间:2023-02-26 22:10:02

您可以尝试创建与您返回的类型相同的类型:

You could try creating the same type you are returning:

List<HashMap<String, String>> = new ArrayList<HashMap<String, String>>();

不需要声明实现类型,即ArrayList.List 接口更通用,因此在将变量声明为具体类型时,问问自己是否有必要这样做.看针对接口编程

There is no need to declare the implementation type, i.e. ArrayList. The List interface is more general, so when declaring variables as a concrete type, ask yourself if this is necessary. See Programming against interface