/
LuvDyrachyo
/
Java_assignments
Обзор
Документация
Войти
/
LuvDyrachyo
/
Java_assignments
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
java-oop-ru/subtyping/examples/Example.java
30 строк
771 B
@hexlet/cli
submit java-oop-ru/subtyping
24 янв 2024, 18:42
24 янв 2024, 18:42
331f380
Код
Авторство
О чём код?
package exercise; import java.util.List; public class Example { public static void main(String[] args) { Device ipad = new IPad(); Device iphone = new IPhone(); Device galaxyNote = new GalaxyNote(); for (Device device: List.of(ipad, iphone, galaxyNote)) { device.game(); } // 1 List.of(ipad, iphone, galaxyNote).stream() .filter(device -> device instanceof Smartphoneable) .map(device -> (Smartphoneable) device) .forEach(Smartphoneable::call); //2 for (Device device: List.of(ipad, iphone)) { if (device instanceof Smartphoneable) { ((Smartphoneable) device).call(); } } } }