consider the following code:
public class ListDemo {
List<Inner> inners;
public ListDemo() {
this.inners = new ArrayList<>();
}
private void load(){
SomeClzz.load(inners);
}
private class Inner implements TestInterface {
@Override
public void bla() {
System.out.println("Bla");
}
}
}
with the interface:
public interface TestInterface {
public void bla();
}
and the class:
public class SomeClzz {
public static void load(List<TestInterface> test){
for (TestInterface testInterface : test) {
testInterface.bla();
}
}
}
I created this fake code based on a real world example, because I wanted to see if I could isolate the issue and found the that the load method had an error.
Why is it that SomeClzz.load(inners);
gives an error that inners can't be cast from a List<Inner>
to a List<TestInterface>
?