Interface List - java

后端 未结 2 1074
小鲜肉
小鲜肉 2021-01-28 14:27

We have been asked to replace ArrayList and use interface List instead in two classes. I\'ve been trying but to no avail. If someone could help with one of the classes to show h

相关标签:
2条回答
  • 2021-01-28 14:50

    Change abstract public void act(ArrayList newAnimals); to abstract public void act(List newAnimals);

    and in method body do newAnimals = new ArrayList();

    0 讨论(0)
  • 2021-01-28 14:52

    "List" is an interface, therefore it cannot be instantiated. Replace all declarations that are now ArrayList with List, where x is the class contained by the container. But, leave the instantiation the same (List<x> = new ArrayList<x>(); is valid). It's a simple change but the code you provided is clearly incomplete.

    At the risk of sounding like a troll, you should also tag this "homework" or seek employment elsewhere unless you strongly feel that this change is justified in your code.

    0 讨论(0)
提交回复
热议问题