Java – map
How to convert map < object, Object > mapping < string, string > in the cleanest way?
Is there a way not to iterate the map?
thank you
Solution
I think it's a good idea to explain why simple solutions don't work and why you'll never use this
Suppose you can convert map < Object > map < string & gt What do you want to happen from the following code:
Map<Object> m = Something; m.add("Looks good."); m.add(new Integer(42)); Map<String> s = (Map<String>)m; // uhuh,no we don't want that.
Now you can use the Bohemian / Chris solution, but you basically destroy the Java type system Don't do this. You don't need the map < string > to contain an integer! Interesting later debugging - the additional code that loops through all variables will avoid a lot of headaches, almost not a performance issue.
If there is reason to claim that the map takes objects instead of strings, someone may add any objects - usually you should be able to avoid this better generalization