赞
踩
编译环境:Eclipse
问题:编译集合类型List、Set、Map代码时,编译器出现下面的警告:
- List is a raw type. References to generic type List<E> should be parameterized
- Set is a raw type. References to generic type Set<E> should be parameterized
- Map is a raw type. References to generic type Map<K,V> should be parameterized
具体的问题代码:
- List addressList;
-
- public void setAddressList(List addressList) {
- this.addressList=addressList;
- }
- public List getAddressList() {
- System.out.println("List Elements :" + addressList);
- return addressList;
- }
警告的内容是,需要我们给出数据的原始类型,具体的修改方法如下:
- List<String> addressList;
-
- public void setAddressList(List<String> addressList) {
- this.addressList=addressList;
- }
- public List<String> getAddressList() {
- System.out.println("List Elements :" + addressList);
- return addressList;
- }
问题下成功解决。
Set集合类型跟List集合类型一样,具体说一下Map集合类型。
Map、HashMap集合类型问题总结:(因为这两种集合类型都需要指出具体的key值和value值)
- 问题:
- Map.Entry is a raw type. References to generic type Map<K,V>.Entry<K,V> should be parameterized
- 解决方法:
- HashMap<Object, Object> addressHash;
- HashMap<String, Long> addressHash;
- Map<String, Long> addressMap;
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。