Java – pass the map to the method that needs the map

I have a method with the following signature

public static ActionDeFinition reverse(String action,Map<String,Object> args)

I have methods to return the following:

public static Map<String,String> toMap(String value)

Is there any method to convert the output of the tomap to reverse use, for example:

ActionDeFinition ad = reverse("Action.method",toMap("param1=value1,param2=value2"));

I need to do something

(Map<String,Object>) toMap("param1=value1,param2=value2");

But I can't do that

I have also tried the following methods

public static Map<String,String> toMap(String value) {
    Map<String,Object> source = toMap(value);
    Map<String,String> map = new LinkedHashMap<String,String>();

    for(Map.Entry<String,Object> entry: source.entrySet()) {
        map.put(entry.getKey(),(String) entry.getValue());
    }

    return map;
}

But I think because of type erasure, I know that the method is repeated

Any ideas?

edit

I forgot to state that I can't change the reverse method, as many people suggest

Solution

If you can change the way you want

public static ActionDeFinition reverse(String action,? extends Object> args)
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>