Skip to content

Instantly share code, notes, and snippets.

@internetova
Created November 24, 2020 19:49
Show Gist options
  • Save internetova/4cee109fe97e285c6102fc78ef32d32f to your computer and use it in GitHub Desktop.
Save internetova/4cee109fe97e285c6102fc78ef32d32f to your computer and use it in GitHub Desktop.
/*
Представьте, что разрабатывайте фентезийную игру.
В игре есть гоблины и орки. Они спавнятся в пещерах.
Создайте классы:
Goblin
Hobogoblin extends Goblin
Orc
Lair - пещера гоблинов, которая может вмещать в себя только гоблинов и наследников
Создайте экземпляр класса Lair. В качестве типа поставьте гоблина, хогоблина и орка. Результат опишите в комментариях
*/
void main() {
final lair1 = Lair<Goblin>();
final lair2 = Lair<Hobogoblin>();
// final lair3 = Lair<Orc>(); Ошибка: 'Orc' doesn't extend 'Goblin'
}
class Goblin {}
class Hobogoblin extends Goblin {}
class Orc {}
class Lair<T extends Goblin> {}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment