@@ -332,37 +332,38 @@ public <T> T getBean(Class<T> requiredType) throws BeansException {
332
332
}
333
333
334
334
@ Override
335
+ @ SuppressWarnings ("unchecked" )
335
336
public <T > T getBean (Class <T > requiredType , Object ... args ) throws BeansException {
336
337
Assert .notNull (requiredType , "Required type must not be null" );
337
- String [] beanNames = getBeanNamesForType (requiredType );
338
+ String [] candidateNames = getBeanNamesForType (requiredType );
338
339
339
- if (beanNames .length > 1 ) {
340
- ArrayList <String > autowireCandidates = new ArrayList <String >();
341
- for (String beanName : beanNames ) {
340
+ if (candidateNames .length > 1 ) {
341
+ List <String > autowireCandidates = new ArrayList <String >(candidateNames . length );
342
+ for (String beanName : candidateNames ) {
342
343
if (!containsBeanDefinition (beanName ) || getBeanDefinition (beanName ).isAutowireCandidate ()) {
343
344
autowireCandidates .add (beanName );
344
345
}
345
346
}
346
347
if (autowireCandidates .size () > 0 ) {
347
- beanNames = autowireCandidates .toArray (new String [autowireCandidates .size ()]);
348
+ candidateNames = autowireCandidates .toArray (new String [autowireCandidates .size ()]);
348
349
}
349
350
}
350
351
351
- if (beanNames .length == 1 ) {
352
- return getBean (beanNames [0 ], requiredType , args );
352
+ if (candidateNames .length == 1 ) {
353
+ return getBean (candidateNames [0 ], requiredType , args );
353
354
}
354
- else if (beanNames .length > 1 ) {
355
+ else if (candidateNames .length > 1 ) {
355
356
Map <String , Object > candidates = new LinkedHashMap <String , Object >();
356
- for (String beanName : beanNames ) {
357
+ for (String beanName : candidateNames ) {
357
358
candidates .put (beanName , getBean (beanName , requiredType , args ));
358
359
}
359
360
String primaryCandidate = determinePrimaryCandidate (candidates , requiredType );
360
361
if (primaryCandidate != null ) {
361
- return getBean ( primaryCandidate , requiredType , args );
362
+ return ( T ) candidates . get ( primaryCandidate );
362
363
}
363
364
String priorityCandidate = determineHighestPriorityCandidate (candidates , requiredType );
364
365
if (priorityCandidate != null ) {
365
- return getBean ( priorityCandidate , requiredType , args );
366
+ return ( T ) candidates . get ( priorityCandidate );
366
367
}
367
368
throw new NoUniqueBeanDefinitionException (requiredType , candidates .keySet ());
368
369
}
@@ -1477,7 +1478,7 @@ private class DependencyObjectFactory implements ObjectFactory<Object>, Serializ
1477
1478
public DependencyObjectFactory (DependencyDescriptor descriptor , String beanName ) {
1478
1479
this .descriptor = new DependencyDescriptor (descriptor );
1479
1480
this .descriptor .increaseNestingLevel ();
1480
- this .optional = this .descriptor .getDependencyType (). equals ( javaUtilOptionalClass );
1481
+ this .optional = ( this .descriptor .getDependencyType () == javaUtilOptionalClass );
1481
1482
this .beanName = beanName ;
1482
1483
}
1483
1484
@@ -1541,7 +1542,7 @@ public Object getOrderSource(Object obj) {
1541
1542
if (beanDefinition == null ) {
1542
1543
return null ;
1543
1544
}
1544
- List <Object > sources = new ArrayList <Object >();
1545
+ List <Object > sources = new ArrayList <Object >(2 );
1545
1546
Method factoryMethod = beanDefinition .getResolvedFactoryMethod ();
1546
1547
if (factoryMethod != null ) {
1547
1548
sources .add (factoryMethod );
0 commit comments