Учитывая следующий код:Доступ атрибута внешнего класса из экземпляра внутреннего класса
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");
//...
Что я могу поменять с моим псевдо-код линией, так что я могу сравнить значения п для двух случаев Внутреннего класса?
Попытка очевидное решение (n != that.n
) не компилируется:
Outer.java:10: cannot find symbol
symbol : variable n
location: class Outer.Inner
if (n != that.n) // pseudo-code line
я вижу .... (МНВ) – miku