mercredi 7 décembre 2016

Java: error: Class is not abstract and does not override abstract method accept(Visitor). While implementing Visitor

I'm trying to implement a Visitor design pattern, I have a class structure with a lot of classes and variable return types between the operation I want to do with the visitor.

I am getting a lot of the compile error Classname is not abstract and does not override abstract method accept(Visitor) in Visitable despite having followed the visitor pattern strictly.

For example my class Add

public class Add extends BinaryExpression implements Visitable {
 /* content of the class supressed */
   public int accept(Visitor v) {
      return v.visit(this); 
    }        
}

In the case of the visitor for the Add class it will always return int, but the visitor for some other classes will return other types or even variable types within the same class.

On my visitable interface I have

public interface Visitable<T> {
  public T accept(Visitor v);}

Using generic types for the variable return types.

Aucun commentaire:

Enregistrer un commentaire