How to avoid large if-statements and instanceof

前端 未结 9 2382
盖世英雄少女心
盖世英雄少女心 2020-11-29 05:11

Animal

public abstract class Animal {
 String name;

 public Animal(String name) {
  this.name = name;
 }

}

Lion<

9条回答
  •  我在风中等你
    2020-11-29 05:54

    If your method is not polymorphic you can't do without the cast. To make it polymorphic, declare a method in the base class and override it in the descendant classes.

提交回复
热议问题