且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在 Java 中声明一个 LinkedList

更新时间:2022-12-23 11:52:25

LinkedList ob = new LinkedList() 不是 100% 正确吗?

Isn't LinkedList ob = new LinkedList() 100% correct?

好吧,我建议使用通用形式,但可以肯定 - 如果您想使用 特定LinkedList 的功能,您需要相应地声明变量.

Well I'd suggest using the generic form, but sure - if you want to use functionality which is specific to LinkedList, you need to declare the variable accordingly.

您可能想要检查 DequeQueue 接口有你想要的.如果他们这样做,请使用那些与描述您需要什么而不是您将使用什么实现的想法保持一致的内容.

You might want to check whether the Deque<E> or Queue<E> interfaces have what you want though. If they do, use those in-keeping with the idea of describing what you need rather than what implementation you'll use.