给定以下代码:
public class Outer
{
public final int n;
public class Inner implements Comparable<Inner>
{
public int compareTo(Inner that) throws ClassCastException
{
if (Outer.this.n != Outer.that.n) // pseudo-code line
{
throw new ClassCastException("Only Inners with the same value of n are comparable");
//...
我可以用我的伪代码行交换什么,以便我可以比较 Inner 类的两个实例的 n 值?
尝试明显的解决方案 ( n != that.n
) 无法编译:
Outer.java:10: cannot find symbol
symbol : variable n
location: class Outer.Inner
if (n != that.n) // pseudo-code line