简体   繁体   中英

Incompatible Types when when using a list of generic class in an interface

I'm using java 1.8 and I get this incompatibility error.

public interface AVCR<T extends ACRI> {
    List<CRTIL<T>> getLists();
}

public class CRTIL<T extends ACRI> {
}

class BV {
    public AVCR<? extends ACRI> getDeafult() {
       return;
    }

    public List<CRTIL<? extends ACRI>>
        getTypeLists() {
        return getDefault().getLists();
        //Incompatible types
    }

}

The compiler error: found

List<? extends CRTIL<? extends ACRI>>

and requires

List<CRTIL<? extends ACRI>>

I am not sure if I understand your question correctly as you do not provide a minimal working example but I try:

You could change the method signature of getTypeLists as follows

public List<? extends CRTIL<? extends ACRI>> getTypeLists()

since you are returning a list of type ? extends CRTIL<? extends ACRI> ? extends CRTIL<? extends ACRI> ? extends CRTIL<? extends ACRI> and not of type CRTIL<? extends ACRI> CRTIL<? extends ACRI> .

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