Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to cast List<Map<?, ?>> into List<Map<String, String>>?

Tags:

java

casting

I am making bukkit plugin and one function returns List<Map<?, ?>>, if I to do that:

List<Map<String, String>> circle = FileManager.area.getMapList("circles");

I get error that it can't be converted. What do to?

The error:

List<Map<?, ?>> cannot be converted into List<Map<String, String>>
like image 302
XsergeiX Avatar asked Jan 06 '15 18:01

XsergeiX


1 Answers

You can cast away all the generics by casting to the raw type, (List):

List<Map<String, String>> circle = (List) FileManager.area.getMapList("circles");

Note that as with most casts this is unsafe - it's better to find a way to pass the correct type information through, as other answers suggest.

like image 132
lmm Avatar answered Sep 21 '22 10:09

lmm