在Java中声明LinkedList [英] Declaring a LinkedList in Java

查看:175
本文介绍了在Java中声明LinkedList的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我总是学习当我们声明一个我们应该做的集合,接口ob = new Class(),如果我想使用一个LinkedList我会做 List ob = new LinkedList(),但是我不能访问LinkedList中的所有方法。 LinkedList ob = new LinkedList ) 100%correct?

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 LinkedList(), but then i can't have access to all methods from LinkedList.. Isn't LinkedList ob = new LinkedList() 100% correct?

推荐答案


不是LinkedList ob = new LinkedList

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

我建议使用泛型形式,但是肯定 - 如果你想使用特定 code> 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.

您可能想检查 Deque< E> 队列< E> 接口有你想要的。如果他们这样做,那么使用那些符合描述你需要什么的想法,而不是你将使用的实现。

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.

这篇关于在Java中声明LinkedList的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆