Supposing I have the following classes:
abstract class A {
static abstract class _Foo {}
}
class B extends A {
static void doSomething() {
System.out.println(C.saySomething());
}
static _Foo getInner() {
return new C._Foo();
}
static abstract class _Foo extends A._Foo {}
}
final class C extends D {
static String saySomething() {
return "Something";
}
}
abstract class D {
static class _Foo extends B._Foo {
public int value() {
return 42;
}
}
}
To provide some context:
- All of these classes reside in the same package.
- Class
C
andD
are generated at compile time - Class
A
as well asC
are never instantiated; they simply provide some behaviour for classB
- Class
B
is the only one that is actually used. - Class
D
is unknown until after compile time, which is why we are only usingC
inB
.
This is similar to what one might expect when working with google autovalue
My question is with regards to the getInner
function in B
:
- Which
_Foo
will be instantiated at the linereturn new C._Foo();
? The_Foo
inD
or the one inA
? - Is this undefined behaviour as to which gets instantiated or is it documented? Please provide documentation if possible
- How is the order determined?
The last question is just as an FYI, I'm mostly interested in the first two.
Thanks for your help.