当前位置:   article > 正文

List is a raw type. References to generic type List should be parameterized

List is a raw type. References to generic type List should be parameterized

编译环境:Eclipse

问题:编译集合类型List、Set、Map代码时,编译器出现下面的警告:

  1. List is a raw type. References to generic type List<E> should be parameterized
  2. Set is a raw type. References to generic type Set<E> should be parameterized
  3. Map is a raw type. References to generic type Map<K,V> should be parameterized

具体的问题代码:

  1. List addressList;
  2. public void setAddressList(List addressList) {
  3. this.addressList=addressList;
  4. }
  5. public List getAddressList() {
  6. System.out.println("List Elements :" + addressList);
  7. return addressList;
  8. }

  

警告的内容是,需要我们给出数据的原始类型,具体的修改方法如下:

  1. List<String> addressList;
  2. public void setAddressList(List<String> addressList) {
  3. this.addressList=addressList;
  4. }
  5. public List<String> getAddressList() {
  6. System.out.println("List Elements :" + addressList);
  7. return addressList;
  8. }

问题下成功解决。

Set集合类型跟List集合类型一样,具体说一下Map集合类型。

Map、HashMap集合类型问题总结:(因为这两种集合类型都需要指出具体的key值和value值)

  1. 问题:
  2. Map.Entry is a raw type. References to generic type Map<K,V>.Entry<K,V> should be parameterized
  1. 解决方法:
  2. HashMap<Object, Object> addressHash;
  3. HashMap<String, Long> addressHash;
  4. Map<String, Long> addressMap;

 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/从前慢现在也慢/article/detail/463592
推荐阅读
相关标签
  

闽ICP备14008679号