gpt4 book ai didi

java - 嵌套 HashMap 和声明

转载 作者:行者123 更新时间:2023-11-30 03:51:41 26 4
gpt4 key购买 nike

我正在尝试使用 Map 进行实验,但我有这样的疑问:

Map<String, Object> input = new LinkedHashMap<String, Object>();
String operator = "in";
String argument = "foo";
String field = "AvailabilityStatus";
Map<String, Object> innerMap = new LinkedHashMap<String, Object>();
innerMap.put(operator, argument);
input.put(field, innerMap);

上述代码的函数调用是

String output = FunctionA(input);

似乎工作正常,但将输入更改为:

Map<String, Map<String, Object>> input = new LinkedHashMap<String, LinkedHashMap<String, Object>>();

不允许我以同样的方式调用该函数。 functionA 是:

public static String FunctionA(Map<String, Object> filters) throws Throwable {
//logic goes here
}

这两个声明本质上不是想做同样的事情吗?

最佳答案

或者,您可以像这样创建 FunctionA 方法:

public static String FunctionA(Map<String, ? extends Object> filters) throws Throwable{
//logic goes here
}

这样做会很快乐!

FunctionA(new HashMap<String, LinkedHashMap<String, Object>>());

关于java - 嵌套 HashMap 和声明,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24272710/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com