howto instatiate array of inner classes

Hi, I couldn't find the syntax for doing this.

I just want to instantiate an array of inner classes (non-static). It says '(' expected.

Here is a small sample:

public class test_inner {

public class inner1 {

}

public inner1 inner1_inst;

public class inner2 {

}

public inner2[] inner2_ar;

public static void foo() {

test_inner inst = new test_inner(); // OK

inst.inner1_inst = inst.new inner1(); // OK, single inst

inst.innter2_ar = inst.new inner2[10]; // fails to compile

// also tried [10]() even ()[10] ...

}

}

Using java 1.6 Win32.

As always grateful for any help.

[686 byte] By [Developer_Named_Aarona] at [2007-11-27 9:22:17]
# 1

I don't know why this doesn't work, but why isn't the outer class instantiating its own members? Very unusual.

public inner1 inner1_inst = new inner1();

public inner2[] inner2_ar = new inner2[10];

ejpa at 2007-7-12 22:16:40 > top of Java-index,Java Essentials,Java Programming...
# 2

The following compiles OK:public class test_inner {

public class inner1 {}

public inner1 inner1_inst;

public class inner2 {}

public inner2[] inner2_ar;

public static void foo() {

test_inner inst = new test_inner();

inst.inner1_inst = inst.new inner1();

inst.inner2_ar = new test_inner.inner2[10];

// inst.inner2_ar = inst.new inner2[10]; // fails to compile

// also tried [10]() even ()[10] ...

}

}

When creating inst.inner2_ar you don't use a qualified class instance creation expression (JLS 15.9) because what is being created is not an inner member class: it's an array. So the syntax for creating it is that of JLS 15.10.

pbrockway2a at 2007-7-12 22:16:40 > top of Java-index,Java Essentials,Java Programming...
# 3
OK makes sense when you explain it that way :-) thanks.
Developer_Named_Aarona at 2007-7-12 22:16:40 > top of Java-index,Java Essentials,Java Programming...