gpt4 book ai didi

java - 不兼容的类型,预期的 hashmap 找到了 String

转载 作者:行者123 更新时间:2023-12-02 07:52:33 24 4
gpt4 key购买 nike

public class Readparam
{
private static String method_name;
public static HashMap<String, Vector<String>> getParameters(String file_name)
{
HashMap temp_map = new HashMap();

String current_dir = System.getProperty("user.dir");

File new_file = new File(current_dir + "\\parameters\\" + file_name);

StringTokenizer stringtok = null;
StringBuffer temp_contents = new StringBuffer();

BufferedReader input = null;
try
{
input = new BufferedReader(new FileReader(new_file));
String current_line = null;

while (((current_line = input.readLine()) != null) && (current_line.length() > 0))
{
stringtok = new StringTokenizer(current_line, "(");

method_name = stringtok.nextToken();

String parsed_parameters = current_line.subSequence(current_line.indexOf("(") + 1, current_line.indexOf(")")).toString();

StringTokenizer paramtok = new StringTokenizer(parsed_parameters, ",");

String[] parsed_string = parsed_parameters.split(", ");
String parsing = method_name + "(";

for (int i = 0; i < parsed_string.length; i++)
{
String[] temp_parse = parsed_string[i].split(" ");
if (i < parsed_string.length - 1)
parsing = parsing + temp_parse[0] + ", ";
else {
parsing = parsing + temp_parse[0];
}
}
parsing = parsing + ")";

Vector temp_vector = new Vector();
for (String s : parsed_string) {
temp_vector.add(s);
}
temp_map.put(parsing, temp_vector);
}
}
catch (FileNotFoundException ex)
{
System.out.println("File not found: " + file_name);
String method_name = null;
return method_name;
}

对此的任何帮助表示赞赏我有最后一行“返回无法编译的方法名我收到错误不兼容的类型,预期 java.util.hashmap 找到 java.lang.String最后一行 return method_name 无法编译

最佳答案

System.out.println("File not found: " + file_name);
HashMap<String, Vector<String>> method_name = null;
return method_name;

由于您的方法属于某种类型,因此您需要将返回的值“转换”为该类型。

如果您使用 Eclipse 进行编码,您只需单击小错误图标,它就会为您修复错误,并为您转换错误。如果您不使用 Eclipse,以后可能会考虑它。 (NetBeans 以类似的方式工作)

关于java - 不兼容的类型,预期的 hashmap 找到了 String,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10053213/

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