您现在的位置是:主页 > news > 网站域名怎么做/班级优化大师下载
网站域名怎么做/班级优化大师下载
admin2025/6/3 11:50:25【news】
简介网站域名怎么做,班级优化大师下载,wordpress悬浮按钮插件,做网站需要几个服务器我使用java.util.Hashtable创建了一个Java字典,其中2个字符串的字符串作为键,而int作为值.class pair{public e one;public f two;}我曾经在上述类中初始化字典:Dictionary, Integer> dict new Hashtable();现在,我无法检查dict中是否存在密钥,这意味着我无法将…
我使用java.util.Hashtable创建了一个Java字典,其中2个字符串的字符串作为键,而int作为值.
class pair{
public e one;
public f two;
}
我曾经在上述类中初始化字典:
Dictionary, Integer> dict = new Hashtable();
现在,我无法检查dict中是否存在密钥,这意味着我无法将字符串对作为dict.containsKey()方法的参数传递.
解决方法:
尝试这样的事情:
public class Pair {
private final E e;
private final F f;
public Pair(E e, F f) {
this.e = e;
this.f = f;
}
public E getE() {
return e;
}
public F getF() {
return f;
}
@Override
public boolean equals(Object obj) {
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
final Pair other = (Pair) obj;
if (!this.e.equals(other.getE())) {
return false;
}
if (!this.f.equals(other.getF())) {
return false;
}
return true;
}
@Override
public int hashCode() {
hash = 53 * e.hashCode() + f.hashCode();
return hash;
}
}
我假设e和f不为null.如果可以为null,则必须在if(e.equals(other.getE()))之前检查e == null是否阻止NPE.
进一步说明:
标签:dictionary,tuples,java
来源: https://codeday.me/bug/20191119/2038910.html