Forums Register Login

generics - map of lists

+Pie Number of slices to send: Send
Hi all

On the following code
Compiler is giving this warning (line 1):
List is a raw type. References to generic type List<E> should be parameterized





What is the correct way to init levelsMap ?

Thank you very much
Sharon
+Pie Number of slices to send: Send

After all, you don't want to insert lists, you want to insert lists of strings.
+Pie Number of slices to send: Send
Thank you!
on the same matter, for this code :

The compiler gives warning for
Type safety: The expression of type List needs unchecked conversion to conform to List<String>
Why is that?

Thank you
Sharon
[ September 24, 2007: Message edited by: Sharon whipple ]
+Pie Number of slices to send: Send
I can't be sure without seeing the code, but my guess is that query.getResultList() returns List, not List<String>.

You can either modify query.getResultList() to return List<String> instead, or if you can't (because it's not your code) put the following line above this one:

This will remove the warning, but it is really better to change the code of query.getResultList() instead.

For anyone who says you can cast to (List<String> ) instead of suppressing warnings, that cast will cause a warning as well
[ September 24, 2007: Message edited by: Rob Prime ]
+Pie Number of slices to send: Send
Modify your code to:

HashMap<String,List<String>> levelsMap = new HashMap<String,List<String>>();


It will be fine. Did that answer your question?
+Pie Number of slices to send: Send
At most occasions, we say:

Map<String,List<String>> levelsMap = new HashMap<String,List<String>>();


Using interface gives you more flexible, and it's the OOP way...
+Pie Number of slices to send: Send
 

Originally posted by Huan Niu:
Modify your code to:

HashMap<String,List<String>> levelsMap = new HashMap<String,List<String>>();

It will be fine. Did that answer your question?




Yes it answered my question. thank you

About the interfaces this code is imported code from other department = anyway I will be glad to hear other implementation suggestion.

About the query.getResultList()
What I don't understand is why query.getResultList() not generify?
(Query class: javax.persistence.Query) in Javaee-5.0.jar.
+Pie Number of slices to send: Send
Yes, unfortunately EJB 3.0 Persistence did not generify their collections, and the Query.getResultList() returns a List and not a List<Object>. You can't cast your way out of a compiler warning (without other settings sent to the compiler).

So (as of Nov 2007),



This is something that EJB Persistence needs to fix.
It likely won't happen until mid 2008.
Make a note of these in your code so you can go clean them up later!
Ruth Stout was famous for gardening naked. Just like this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 13650 times.
Similar Threads
if isEmpty or null
Confusion with generics
confuse statement ?
Transforming a class instance to fit into the generic bracket
generics and maps
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 23:24:36.