dimanche 22 mai 2022

Java Generics Compiler Error in Chain of Responsibility design principle

public abstract class AbstractExecutor<PARAM, RET> {

private AbstractExecutor<?, ?> nextExecutor;
    
public abstract RET execute(PARAM param);

public void executeAll(PARAM par) {
    System.out.println("Executing..");
    RET ret= execute(par);
     if(this.nextExecutor!=null){
         System.out.println("Executing.." + this.getClass());
            this.nextExecutor.executeAll(ret);
        }
}

public AbstractExecutor<?, ?> setNextExecutor(AbstractExecutor<?,?> next){
    this.nextExecutor = next;
    return this.nextExecutor;
}}

Can anyone help me with this code, why I am wrong here "this.nextExecutor.executeAll(ret);" ? I am getting "The method executeAll(capture#4-of ?) in the type AbstractExecutor<capture#4-of ?,capture#5-of ?> is not applicable for the arguments (RET)" but unable to understand whats wrong here? How to correct this ?

Aucun commentaire:

Enregistrer un commentaire