0

I'm trying to make a 2-Dimensional LinkedList in Java and this is what I have come up with:

LinkedList<LinkedList<String>> rows = new LinkedList()<LinkedList<String>>;

Eclipse keeps giving me the following error at the final two alligator brackets:

Syntax error on token ">>", Expression expected after this token

What do I need to do to fix it? What is this error? and Why am I getting it?

4

1 に答える 1

4

括弧はLinkedList宣言の最後に配置する必要があります。そうしないと、コンパイラは生の型が使用されていると想定し、後続のトークンを解析しようとして失敗します。使用する:

LinkedList<LinkedList<String>> rows = new LinkedList<LinkedList<String>>();

以下を使用して、インターフェースへのより良いコード。

List<List<String>> rows = new LinkedList<List<String>>();

これにより、後でリファクタリングが必要になった場合に追加されるList以外の実装タイプが可能になります。LinkedList

于 2013-05-10T22:48:52.550 に答える