Implement a Java interface with an additional method in the class implementation

First post, so be careful. :) I'm not sure what I'm doing wrong here, hope someone can help me.

I have a class that implements the List interface. This class also has its own method, which will add only an item to the list, if it is not already included in the list. The problem is that when I try to use my conditionalAdd method, I get an error message indicating that it cannot find my method because it is looking for it in the WorkflowSubType class. See below:

When I instantiate the class, I use:

List<WorkflowSubType> currentViolations = new Violations();

This is the definition of my class that implements the List interface:

import java.util.*;

public class Violations<E> implements List<E>{

public Violations() {}

public void conditionalAdd(E violation){
     if(violation != null)
     if(!this.contains(violation))
    add(violation);
}

@Override
public <T> T[] toArray(T[] a) {
return null;
}

@Override
public boolean add(E e) {
return false;
}

 @Override....

, conditionalAdd. Violations, , List, "". ?

. RW

+4
1

"". , , List conditionalAdd. : ((Violations<WorkflowSubType>)currentViolations).conditionalAdd(whatever);

+1

Source: https://habr.com/ru/post/1531445/


All Articles