Declaring a LinkedList in Java

前端 未结 11 1868
北荒
北荒 2021-02-20 14:26

I always learn when we declare a collection we should do, Interface ob = new Class(), if i want to use for example a LinkedList i\'ll do List ob = new LinkedL

11条回答
  •  半阙折子戏
    2021-02-20 14:53

    Nope.. This would be wrong, at the later stages if he wants to change his implementation from linked list to any other implementation of list type he will go wrong... So better to use the interface level declaration.

提交回复
热议问题