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
  • 20,148
  • 14
  • 73
  • 129
assaf.gov
  • 517
  • 6
  • 19
  • 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
  • 393
  • 3
  • 17