0

I have a method that receives 2 parameters: List of interface. I get an error when I try to call this method with List of class that implements that interface.

The input must be of type class, I don't want to change it to List of interface.

List<Io> oldList;
List<Io> newList;
handleIo(oldList, newList); //Here I get the error

public void handleIo(List<IIo> oldIos, List<IIo> newIos) {...}

public class Io implements IIo {...}

public interface IIo {...}

I thought this is the idea of interfaces, I can't figure out what is wrong. The error asking to change the type of the parameters I send to the method.

zappee
  • 16,326
  • 13
  • 62
  • 109
assaf.gov
  • 387
  • 3
  • 16
  • This question and answers explain some of the concepts that you'll need : https://stackoverflow.com/questions/2745265/is-listdog-a-subclass-of-listanimal-why-are-java-generics-not-implicitly-po?rq=1 – racraman Aug 20 '19 at 05:49

1 Answers1

1

First of all you shouldn't start your method with a capital letter (naming conventions are important).

But to your problem: Change the method signature to the following:

public void handleIo(List<? extends IIo> oldIos, List<? extends IIo> newIos)

MaS
  • 353
  • 2
  • 14