protected void init ( int initialMaxSize , Class < T > type , Factory < T > factory ) { this . size = 0 ; this . type = type ; this . factory = factory ; data = ( T [ ] ) Array . newInstance ( type , initialMaxSize ) ; if ( factory != null ) { for ( int i = 0 ; i < initialMaxSize ; i ++ ) { try { data [ i ] = createInstance ( ) ; } catch ( RuntimeException e ) { throw new RuntimeException ( "declareInstances is true, but createInstance() can't create a new instance. Maybe override createInstance()?" ) ; } } } }
Data structure initialization is done here so that child classes can declay initialization until they are ready