编译 apache james server 2.3.1 时无法使用 HashMap
Unable to use HashMap when compiling apache james server 2.3.1
我无法使用同步的 HashMap,因为 james apache server 2.3.1 似乎不允许这样做。
这是我收到的错误消息:
error: generics are not supported in -source 1.4
Map<String, String> list = new HashMap<String, String>();
^
(use -source 5 or higher to enable generics)
1 error
1 warning
这是我在代码中使用它的较短版本。我基本上只是将一些 SQL 结果存储到此列表中。
try {
conn = ......);
String SQL = "SELECT * FROM list";
getListRS = conn.prepareStatement(SQL);
ResultSet rsListResult = getListRS.executeQuery();
Map<String, String> list = new HashMap<String, String>();
while (rsListResult.next()) {
list.put(rsListResult.getString(0), rsListResult.getString(1));
}
rsListResult.close();
conn.close();
}
catch (SQLException se) {
se.printStackTrace();
}
catch (Exception e) {
e.printStackTrace();
}
finally {
try {
if (getListResult != null) {
getListResult.close();
}
}
catch (SQLException se2) {
se2.printStackTrace();
}
try {
if (conn != null) {
conn.close();
}
}
catch (SQLException se) {
se.printStackTrace();
}
}
if (this.list.containsKey(mail.getSender()+"="+mail.getRecipients())) {
System.out.println(list);
return mail.getRecipients();
} else {
System.out.println(listlist);
return null;
}
由于 James 不让我编译,我还可以使用什么其他列表来实现此目的。
错误在这里:
<javac destdir="${build.classes}" debug="${debug}" optimize="${optimize}" deprecation="${deprecation}" target="${jdk.target}" source="${jdk.source}">
这是 java 编译器的错误。 在 Ant 中,您在 javac 标记中定义源级别,例如:
<javac target="1.5" source="1.5" .....>
(或者检查 default.properties 文件中的 jdk.target
和 jdk.source
并将它们更改为 1.5)。
至少使用 1.5 级别以允许泛型。
顺便说一句。要检查 java 版本,您可以在转到 jdk bin 文件夹时调用 java -version
。
由于在 java 1.5 中引入了泛型,您现在所能做的就是使用原始 HashMap 并使用大量检查和强制转换
但最好的办法是升级您的 java 版本