【发布时间】:2010-09-23 12:14:27
【问题描述】:
我正在使用 Apache Commons EqualsBuilder 为非静态 Java 内部类构建 equals 方法。例如:
import org.apache.commons.lang.builder.EqualsBuilder;
public class Foo {
public class Bar {
private Bar() {}
public Foo getMyFoo() {
return Foo.this
}
private int myInt = 0;
public boolean equals(Object o) {
if (o == null || o.getClass() != getClass) return false;
Bar other = (Bar) o;
return new EqualsBuilder()
.append(getMyFoo(), other.getMyFoo())
.append(myInt, other.myInt)
.isEquals();
}
}
public Bar createBar(...) {
//sensible implementation
}
public Bar createOtherBar(...) {
//another implementation
}
public boolean equals(Object o) {
//sensible equals implementation
}
}
除了声明getMyFoo() 方法之外,是否有语法可以引用other 的Foo 参考? other.Foo.this 之类的东西(不起作用)?
【问题讨论】:
标签: java syntax reference inner-classes