Results 1 to 5 of 5
- 01-19-2012, 04:02 AM #1
Generics Q: array of lists of arrays
SSSCE - there are two questions in the comments.
Java Code:import java.util.LinkedList; import java.util.List; public class Foo { public static void main(String[] args) { // i want to create an array of lists of arrays. this seems like the // right syntax, but gives an error: "Cannot create a generic array of // LinkedList<Foo[]>". what is the correct syntax? // List<Foo[]>[] arrayOfLists = new LinkedList<Foo[]>[10]; // this works, but complains about type safety. can I do anything // about this warning other than @SuppressWarnings("unchecked")? List<Foo[]>[] arrayOfLists = new LinkedList[1]; // the declaration is actually already typesafe, because this line // produces a type mismatch error: // arrayOfLists[0] = new LinkedList<String>(); // this works arrayOfLists[0] = new LinkedList<Foo[]>(); } }Get in the habit of using standard Java naming conventions!
- 01-22-2012, 05:29 PM #2
Re: Generics Q: array of lists of arrays
Anyone? Anyone? Bueller?
Get in the habit of using standard Java naming conventions!
-
Re: Generics Q: array of lists of arrays
Look up type erasure as I think that this is causing your problem. It's a basic limitation of Java generics. :(
This may help clarify: http://www.angelikalanger.com/Generi...rs.html#FAQ202
You may be better off creating a List of Lists:
Java Code:List<List<Foo>> listOfLists = new LinkedList<List<Foo>>(); listOfLists.add(new ArrayList<Foo>());Last edited by Fubarable; 01-22-2012 at 05:45 PM.
- 01-22-2012, 05:59 PM #4
Re: Generics Q: array of lists of arrays
Yeah... or for my particular purpose, a Map<Integer, List<Foo>>.
Thanks for that link.Get in the habit of using standard Java naming conventions!
-
Similar Threads
-
array lists in jsp and google api
By gedas in forum New To JavaReplies: 3Last Post: 04-07-2011, 02:18 PM -
generics and passing arrays
By TopNFalvors in forum New To JavaReplies: 0Last Post: 03-17-2011, 04:19 PM -
Array Lists help!!
By lilika in forum New To JavaReplies: 12Last Post: 01-04-2011, 02:05 PM -
Convert arrays into lists
By Richard2732 in forum New To JavaReplies: 2Last Post: 12-28-2009, 08:53 AM -
Help with arrays and array lists
By ambernicole88 in forum New To JavaReplies: 3Last Post: 12-04-2009, 09:47 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks