I'm in the process of porting some C++ code to Java.
Here's a snippet of my code:
class Foo{
...
private class Bar
{
public byte[] data;
public int len;
Bar() {
data = new byte[256];
len = 0;
}
}
...
private Bar[] myArray = new Bar[10];
I want to have an array of 10 objects. But when I want to use the array further in my code, I notice that all 10 members are 'null'.
As a workaround I can solve it with a for-loop in the constructor of the primary class:
Foo() {
for( int i=0; i<myArray.length; i++ )
myArray[i] = new Bar();
}
Is there a better way to call the 10 constructors at once, without the need for a for-loop?