好的,设置如下:
EnclosingClass {
public interface ClassFactory {
public static SomeClass getInstance(int which);
}
private static ClassFactoryImpl {
@Override
public static SomeClass getInstance(int which) {
switch(which) {
case 1:
return new SomeClassSubclassA();
case 2:
return new SomeClassSubclassB();
...
}
}
}
}
我希望能够发表以下声明:
SomeClass x = EnclosingClass.ClassFactory.getInstance(instanceClassRequest);
这可能吗?如果没有,我如何仅通过它实现的接口访问静态嵌套类?