题
所有生成从我们的后端web服务存根具有等于-方法与此类似:
private java.lang.Object __equalsCalc = null;
public synchronized boolean equals(java.lang.Object obj) {
if (!(obj instanceof PropertyData)) return false;
PropertyData other = (PropertyData) obj;
if (obj == null) return false;
if (this == obj) return true;
if (__equalsCalc != null) {
return (__equalsCalc == obj);
}
__equalsCalc = obj;
boolean _equals;
_equals = true &&
((this.key==null && other.getKey()==null) ||
(this.key!=null &&
this.key.equals(other.getKey()))) &&
((this.value==null && other.getValue()==null) ||
(this.value!=null &&
this.value.equals(other.getValue())));
__equalsCalc = null;
return _equals;
}
可有人请向我解释__equalsCalc
的purpoise?我只是不明白这一点。它不是在课堂上使用别的地方。我看到它的方式,它不是空完全“平等”的计算过程。然而等号声明synchronized
。因此,只有一个线程可以在任何给定的时间在它。
我不明白,为什么if (__equalsCalc != null)
应该永远是正确的。
请告诉我我的愚蠢的误解; - )
编辑:我是新来的项目,因此我的答案可能是错误的。但是,如果我正确地跟踪它,是由轴WSDL2Java的产生的方法
解决方案
我怀疑这是试图阻止递归 - 如果有些事情本身作为它的键,你不希望它永远递归
然而,在该点它用参考平等的测试,这可能是不期望的。
什么是生成的代码?它是一个土生土长的系统,或公开招标?如果是土生土长的,是开发商仍负责该公司?
编辑:好了,现在我们知道这是WSDL2Java的,答案是(在某种程度上)在的源代码:
// The __equalsCalc field and synchronized method are necessary
// in case the object has direct or indirect references to itself.
和然后:
// Have we been here before ? return true if yes otherwise false
pw.println(" if (__equalsCalc != null) {");
pw.println(" return (__equalsCalc == obj);");
pw.println(" }");
不评论最具解释,但至少他们展示我们在正确的轨道想着递归的。
其他提示
在__equalsCal表现为用于向等于最后一次调用的高速缓存。因此,如果在同一个实例两次调用equals方法被调用以相同的参数的方法将更快
编辑:对不起这将是真,如果
__equalsCalc = null;
不会在那里,但重新检查你的代码,可能是我的回答是无效的。
不隶属于 StackOverflow