@@ -332,37 +332,38 @@ public <T> T getBean(Class<T> requiredType) throws BeansException {
332332 }
333333
334334 @ Override
335+ @ SuppressWarnings ("unchecked" )
335336 public <T > T getBean (Class <T > requiredType , Object ... args ) throws BeansException {
336337 Assert .notNull (requiredType , "Required type must not be null" );
337- String [] beanNames = getBeanNamesForType (requiredType );
338+ String [] candidateNames = getBeanNamesForType (requiredType );
338339
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 ) {
342343 if (!containsBeanDefinition (beanName ) || getBeanDefinition (beanName ).isAutowireCandidate ()) {
343344 autowireCandidates .add (beanName );
344345 }
345346 }
346347 if (autowireCandidates .size () > 0 ) {
347- beanNames = autowireCandidates .toArray (new String [autowireCandidates .size ()]);
348+ candidateNames = autowireCandidates .toArray (new String [autowireCandidates .size ()]);
348349 }
349350 }
350351
351- if (beanNames .length == 1 ) {
352- return getBean (beanNames [0 ], requiredType , args );
352+ if (candidateNames .length == 1 ) {
353+ return getBean (candidateNames [0 ], requiredType , args );
353354 }
354- else if (beanNames .length > 1 ) {
355+ else if (candidateNames .length > 1 ) {
355356 Map <String , Object > candidates = new LinkedHashMap <String , Object >();
356- for (String beanName : beanNames ) {
357+ for (String beanName : candidateNames ) {
357358 candidates .put (beanName , getBean (beanName , requiredType , args ));
358359 }
359360 String primaryCandidate = determinePrimaryCandidate (candidates , requiredType );
360361 if (primaryCandidate != null ) {
361- return getBean ( primaryCandidate , requiredType , args );
362+ return ( T ) candidates . get ( primaryCandidate );
362363 }
363364 String priorityCandidate = determineHighestPriorityCandidate (candidates , requiredType );
364365 if (priorityCandidate != null ) {
365- return getBean ( priorityCandidate , requiredType , args );
366+ return ( T ) candidates . get ( priorityCandidate );
366367 }
367368 throw new NoUniqueBeanDefinitionException (requiredType , candidates .keySet ());
368369 }
@@ -1477,7 +1478,7 @@ private class DependencyObjectFactory implements ObjectFactory<Object>, Serializ
14771478 public DependencyObjectFactory (DependencyDescriptor descriptor , String beanName ) {
14781479 this .descriptor = new DependencyDescriptor (descriptor );
14791480 this .descriptor .increaseNestingLevel ();
1480- this .optional = this .descriptor .getDependencyType (). equals ( javaUtilOptionalClass );
1481+ this .optional = ( this .descriptor .getDependencyType () == javaUtilOptionalClass );
14811482 this .beanName = beanName ;
14821483 }
14831484
@@ -1541,7 +1542,7 @@ public Object getOrderSource(Object obj) {
15411542 if (beanDefinition == null ) {
15421543 return null ;
15431544 }
1544- List <Object > sources = new ArrayList <Object >();
1545+ List <Object > sources = new ArrayList <Object >(2 );
15451546 Method factoryMethod = beanDefinition .getResolvedFactoryMethod ();
15461547 if (factoryMethod != null ) {
15471548 sources .add (factoryMethod );
0 commit comments