例如,我正在尝试在我的类(MainActivity)中添加一个对象数组
public class MainActivity extends Activity {
private class A {
A(String s) { ..}
}
private static final A[] aList1;
private static final List<A> aList2;
...
两者都对我没问题。
但我不知道如何初始化aList1 或aList2。已经尝试过以下操作:
private static final A[] aList;
static {
a = new A[2];
a[0] = new A("emails");
}
并且还尝试过:
private static final List<A> aList = new ArrayList<A>(){{
add(new A("emails"));
}};
但日食抱怨:No enclosing instance of type MainActivity is accessible. Must qualify the allocation with an enclosing instance of type MainActivity (e.g. x.new A() where x is an instance of MainActivity).
如何解决这个问题?