【发布时间】:2013-12-19 17:18:41
【问题描述】:
我有这个存储成对 int 的类:
static class IntPair {
int a; //JugsNode.a.content;
int b; //JugsNode.b.content;
public IntPair(int a, int b) {
this.a = a;
this.b = b;
}
}
和一个集合定义如下:
static HashSet<IntPair> confs = new HashSet<IntPair>();
现在,这很简单,我如何检查一个特定的IntPair p 对象是否已经包含在这个集合中,而没有任何对其的引用,但只有它的值?更清楚:
IntPair p = new Pair(0, 0);
confs.add(p);
IntPair p1 = new Pair(0, 0);
confs.contains(p1);
显然,最后一次调用返回false。那么,我如何通过仅包含其值来检查该对是否包含在内。
【问题讨论】:
-
顺便说一句。使您的
a和b字段final。