P
Paul J. Lucas
Given:
// Other.java
class Other {
Other( Base b ) {
m_b = b;
}
final Base m_b;
}
// Base.java
class Base {
Base( Other o ) {
m_o = o;
}
final Other m_o;
}
// Derived.java
class Derived extends Base {
static class Inner1 extends Other {
Inner1( Base b ) {
super( b );
}
static class Inner1a extends Other {
// ...
}
}
static class Inner2 extends Other {
// ...
}
Derived() {
super( new Inner1( this ) ); // illegal
}
}
There are many inner classes derived from Other. All of them
need to have a reference to their outermost creating instance
of Derived. (This is machine-generated code in case you're
wondering.) But it's illegal to pass "this" as shown above
(although there is no reason for this restriction since it's
just an address in memory which is already known. C++ has no
such restriction.)
How can I get what I want in Java?
- Paul
// Other.java
class Other {
Other( Base b ) {
m_b = b;
}
final Base m_b;
}
// Base.java
class Base {
Base( Other o ) {
m_o = o;
}
final Other m_o;
}
// Derived.java
class Derived extends Base {
static class Inner1 extends Other {
Inner1( Base b ) {
super( b );
}
static class Inner1a extends Other {
// ...
}
}
static class Inner2 extends Other {
// ...
}
Derived() {
super( new Inner1( this ) ); // illegal
}
}
There are many inner classes derived from Other. All of them
need to have a reference to their outermost creating instance
of Derived. (This is machine-generated code in case you're
wondering.) But it's illegal to pass "this" as shown above
(although there is no reason for this restriction since it's
just an address in memory which is already known. C++ has no
such restriction.)
How can I get what I want in Java?
- Paul