Forums Register Login

List<ArrayList<String>> compile error

+Pie Number of slices to send: Send
Please help to fix this compile error:

List<ArrayList<String>> l = new List<new ArrayList<String>()>();

Description Resource Path Location Type
Syntax error on token "<", [ expected HwServiceImpl.java /com.mycomp.monitoring.war/src/com/mycomp/monitoring/war/service/impl line 172 Java Problem
+Pie Number of slices to send: Send
One (and it may be the only one, but I'm not sure) problem is you're trying to instantiate an interface(List). You should have an ArrayList or LinkedList (or another class that implements List) on the right side of the expression.

Hope that helps!
Janeice
+Pie Number of slices to send: Send
 

.. but I'm not sure) problem is you're trying to instantiate an interface(List)



why not sure ? It is a problem . You cant instantiate interface.
+Pie Number of slices to send: Send
 

Siddhesh Deodhar wrote:

.. but I'm not sure) problem is you're trying to instantiate an interface(List)



why not sure ? It is a problem . You cant instantiate interface.



I'm just not sure if it's the ONLY problem
+Pie Number of slices to send: Send
Please help this compile error "Syntax error on token "<", [ expected".
Thanks.
List<ArrayList<String>> alerts = new ArrayList<new ArrayList<String>()>();

+Pie Number of slices to send: Send
 

albert kao wrote:Please help this compile error "Syntax error on token "<", [ expected".
Thanks.
List<ArrayList<String>> alerts = new ArrayList<new ArrayList<String>()>();



What Java version are you compiling with? Is it 1.5 or greater? Do you know how to check?
+Pie Number of slices to send: Send
So you are populating an ArrayList with ArrayLists? I had a feeling that syntax would still not work.

Uhm.... and this is really a guess.... try getting rid of the second "new." I am thinking that to populate the ArrayList of Arraylists you'll have to do something like this:

This might work:


See if that works any better....
+Pie Number of slices to send: Send
 

albert kao wrote:List<ArrayList<String>> l = new List<new ArrayList<String>()>();



Don't put garbage characters into your type names, the compiler is saying. Try this instead:



What that line of code creates is an ArrayList into which you can store ArrayList<String> objects. You aren't creating any ArrayList<String> objects yet so you don't need a constructor which tries to do that.
+Pie Number of slices to send: Send
You had too many () in the first code snippet.

Rob Prime points out a better way to initialise that: like thisThat way you can add any type of List, not being restricted to ArrayLists.
It's a tiny ad only because the water is so cold.
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 2559 times.
Similar Threads
tiger - doubt in this code ...
Generics question
Generics ? extends
Wildcard character
Generics Casting
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 06:58:15.