@ SuppressWarnings ( "unchecked" ) public < EngineComponent > EngineComponent [ ] getEngineComponents ( Class < EngineComponent > clazz ) { String thisMethodName = "getEngineComponents" ; if ( TraceComponent . isAnyTracingEnabled ( ) && tc . isEntryEnabled ( ) ) { SibTr . entry ( tc , thisMethodName , clazz ) ; } List < EngineComponent > foundComponents = new ArrayList < EngineComponent > ( ) ; // No need to synchronize on jmeComponents to prevent concurrent // modification from dynamic config and runtime callbacks, because // jmeComponents is now a CopyOnWriteArrayList. Iterator < ComponentList > vIter = jmeComponents . iterator ( ) ; while ( vIter . hasNext ( ) ) { JsEngineComponent ec = vIter . next ( ) . getRef ( ) ; if ( clazz . isInstance ( ec ) ) { foundComponents . add ( ( EngineComponent ) ec ) ; } } if ( TraceComponent . isAnyTracingEnabled ( ) && tc . isEntryEnabled ( ) ) { SibTr . exit ( tc , thisMethodName , foundComponents ) ; } // this code is required to get an array of the EngineComponent type. return foundComponents . toArray ( ( EngineComponent [ ] ) Array . newInstance ( clazz , 0 ) ) ; }
The purpose of this method is to get an engine component that can be cast using the specified class . The EngineComponent is not a class name but represents the classes real type . It is not possible to create an Array of a generic type without using reflection .