Declaring a LinkedList in Java

前端 未结 11 2091
北荒
北荒 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:55

    the rule "always code to interfaces" must be taken with some flexibility. what you are suggesting is fine, and as you came to the conclusion, the only option.

    as a side note, coding to concrete classes like this is faster is most JVMs. deciding whether the performance is worth breaking the rule is the hard thing to decide.

提交回复
热议问题