Witam, ucząc się javy napotkałem sytuacje, której nie potrafię wyjaśnić, a więc dla przykładu, jeśli mamy coś takiego:
public interface MyInterface {
void method1();
}
public class TestClass implements MyInterface {
public TestClass() {}
@Override
public void method1() {}
public void method2() {}
}
TestClass testClass = new TestClass();
MyInterface myInterface = new TestClass();
Teraz uzywając obiektu testClass mogę wywołać method1 i method2, a używając obiektu myInterface mogę wywołać tylko method1.
A więc jeśli napiszę taki kod:
List<TestClass> testClassList = new ArrayList<>();
testClassList.forEach();
czemu mogę wywołać metodę forEach skoro w dokumentacji javy jest napisane, że ta metoda należy do klasy ArrayList a nie do interfejsu List?
Z góry dzięki za każdą pomoc