I am still fighting with Java's references. I am not sure if I will ever understand them. Can anybody help me?
A non static inner class can access the enclosing class via Outer.this
. But how can the outer class access the inner this
?
See this example:
class cycle
{
abstract static class Entity
{
abstract static class Attribute
{
abstract static class Value
{
abstract Attribute attribute ();
}
abstract Entity entity ();
abstract Value value ();
}
}
static class Person extends Entity
{
class FirstName extends Attribute
{
class StringValue extends Value
{
Attribute attribute () { return FirstName.this; }
}
Entity entity () { return Person.this; }
Value value () { return this.StringValue.this; }
}
}
public static void main (String[] args)
{
Person p = new Person();
}
}
StringValue
can access FirstName
and FirstName
can access Person
. But how can FirstName
access StringValue
?
I get the error <identifier> expected
in the implementation of value()
? What is the correct syntax?