@@ -252,7 +252,7 @@ public static synchronized void loadProperties() {
252
252
* from
253
253
* @return new <tt>className</tt> instance, or <tt>null</tt>
254
254
*/
255
- public static Object getClassInstance ( String className , Class type ) {
255
+ public static < T > T getClassInstance ( String className , Class < T > type ) {
256
256
if ( className == null || className .trim ().length () == 0 ) {
257
257
return null ;
258
258
}
@@ -277,7 +277,7 @@ public static Object getClassInstance( String className, Class type ) {
277
277
return null ;
278
278
}
279
279
try {
280
- return clazz .newInstance ();
280
+ return type . cast ( clazz .newInstance () );
281
281
}
282
282
catch ( ExceptionInInitializerError e ) {
283
283
warn ( e .getCause () + " loading class " + className );
@@ -304,8 +304,9 @@ public static Object getClassInstance( String className, Class type ) {
304
304
* @param type class which instantiated classes must be assignable from
305
305
* @return list of new <tt>type</tt> instances (may be empty, but not null)
306
306
*/
307
- public static List getClassInstances ( String propertyName , Class type ) {
308
- List instances = new ArrayList ();
307
+ public static <T > List <T > getClassInstances ( String propertyName ,
308
+ Class <T > type ) {
309
+ List <T > instances = new ArrayList <T >();
309
310
310
311
/* Get the property value, if possible. */
311
312
String propVal ;
@@ -323,7 +324,7 @@ public static List getClassInstances( String propertyName, Class type ) {
323
324
for ( StringTokenizer stok = new StringTokenizer ( propVal , ":" );
324
325
stok .hasMoreElements (); ) {
325
326
String cname = stok .nextToken ().trim ();
326
- Object inst = getClassInstance ( cname , type );
327
+ T inst = getClassInstance ( cname , type );
327
328
if ( inst != null ) {
328
329
instances .add ( inst );
329
330
}
@@ -342,12 +343,13 @@ public static List getClassInstances( String propertyName, Class type ) {
342
343
*
343
344
* @param defaultNames array of string
344
345
*/
345
- public static List getClassInstances ( String [] defaultNames ,
346
- String propertyName , Class type ) {
346
+ public static <T > List <T > getClassInstances ( String [] defaultNames ,
347
+ String propertyName ,
348
+ Class <T > type ) {
347
349
Loader .loadProperties ();
348
- List instances = new ArrayList ();
350
+ List < T > instances = new ArrayList < T > ();
349
351
for ( int i = 0 ; i < defaultNames .length ; i ++ ) {
350
- Object instance = getClassInstance ( defaultNames [ i ], type );
352
+ T instance = getClassInstance ( defaultNames [ i ], type );
351
353
if ( instance != null ) {
352
354
instances .add ( instance );
353
355
}
0 commit comments