Reputation: 1379
I have the following config file:
arenas
arena1
info: infotest
info2: info2test
arena2
info: infotest
info2: info2test
So. Now i want to get one arena, and convert it to a arena object, i have a constructor there taking a Map. So i do following:
Arena a = new Arena((Map<String, Object>) getConfig().get("arenas.arena1"));
That is working. But: im getting the following warning in eclipse:
Type safety: Unchecked cast from Object to Map<String,Object>
I undestand why this apperas. but how can i change the way getting the informations to avoid this, so to make a "safe" cast?
And my second question: Now i want to get all the sub Map 's from arenas."" and initialize them when the plugin loads. How can i get all of them? I cannot find something like arenas.getAll() or i dont know.. something like this.. anyone an idea?
Thank you.
Upvotes: 0
Views: 136
Reputation: 2502
For your first question, you can get the configuration section "arena1" and get all of the values as a Map without any warnings. To do this, use:
config.getConfigurationSection("arenas.arena1").getValues(false);
Alternatively, you can just put @SupressWarnings("unchecked")
over the method where you're using that code. Since you know the type you're getting will be a Map, the warning doesn't really mean much, though some developers might consider this bad practice.
For your second question, you can use a similar method. getValues() is essentially a getAll() type of method, it gets a map of all of the keys and values in the section. So you could use:
config.getConfigurationSection("arenas").getValues(false);
Upvotes: 1