简体   繁体   中英

java.lang.ClassCastException: java.util.HashSet incompatible with DTO

public void write(List<? extends Set<DTO>> setOfDTO)
        throws Exception {

    if (!setOfDTO.isEmpty()) 
    {
        Map<BigInteger, String> tempMap = new HashMap<BigInteger, String>();
        for (DTO dto : setOfDTO.get(0)) {...}

Interesting part is, this does not happen always. So I was wondering if this has anything to do with compiler versions or some other factors. I am using Buildforge(Maven) to build these JARs

It should be:

public void write(List<? extends Set<DTO>> setOfDTO) throws Exception {
    if (!setOfDTO.isEmpty()) {
        Map<BigInteger, String> tempMap = new HashMap<BigInteger, String>();
        for (Set<DTO> dto : setOfDTO) {...}
    }
}

Your list contains Set<DTO> and not DTO objects.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM