Skip to content

Commit c5c32ec

Browse files
committed
Refer to static nested classes, not static inner classes
Various parts of the reference manual as well as the Javadoc for AnnotationConfigContextLoaderUtils improperly refer to "static inner classes" even though this terminology does not exist in Java. The Java Language Specification explicitly refers to such classes as "static nested classes." An "inner class" must be non-static by definition.
1 parent e97712b commit c5c32ec

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed

spring-test/src/main/java/org/springframework/test/context/support/AnnotationConfigContextLoaderUtils.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2014 the original author or authors.
2+
* Copyright 2002-2015 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -41,7 +41,7 @@ public abstract class AnnotationConfigContextLoaderUtils {
4141

4242
/**
4343
* Detect the default configuration classes for the supplied test class.
44-
* <p>The returned class array will contain all static inner classes of
44+
* <p>The returned class array will contain all static nested classes of
4545
* the supplied class that meet the requirements for {@code @Configuration}
4646
* class implementations as specified in the documentation for
4747
* {@link Configuration @Configuration}.
@@ -78,7 +78,7 @@ public static Class<?>[] detectDefaultConfigurationClasses(Class<?> declaringCla
7878
if (configClasses.isEmpty()) {
7979
if (logger.isInfoEnabled()) {
8080
logger.info(String.format("Could not detect default configuration classes for test class [%s]: " +
81-
"%s does not declare any static, non-private, non-final, inner classes " +
81+
"%s does not declare any static, non-private, non-final, nested classes " +
8282
"annotated with @Configuration.", declaringClass.getName(), declaringClass.getSimpleName()));
8383
}
8484
}

src/asciidoc/index.adoc

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1791,15 +1791,15 @@ You use the `Class` property in one of two ways:
17911791
****
17921792
.Inner class names
17931793
If you want to configure a bean definition for a `static` nested class, you have to use
1794-
the __binary__ name of the inner class.
1794+
the __binary__ name of the nested class.
17951795

17961796
For example, if you have a class called `Foo` in the `com.example` package, and this
1797-
`Foo` class has a `static` inner class called `Bar`, the value of the `'class'`
1797+
`Foo` class has a `static` nested class called `Bar`, the value of the `'class'`
17981798
attribute on a bean definition would be...
17991799

18001800
`com.example.Foo$Bar`
18011801

1802-
Notice the use of the `$` character in the name to separate the inner class name from
1802+
Notice the use of the `$` character in the name to separate the nested class name from
18031803
the outer class name.
18041804
****
18051805

@@ -20060,20 +20060,20 @@ the discussion of __`@Bean` Lite Mode__.
2006020060
If you omit the `classes` attribute from the `@ContextConfiguration` annotation, the
2006120061
TestContext framework will attempt to detect the presence of default configuration
2006220062
classes. Specifically, `AnnotationConfigContextLoader` and
20063-
`AnnotationConfigWebContextLoader` will detect all static inner classes of the test class
20063+
`AnnotationConfigWebContextLoader` will detect all `static` nested classes of the test class
2006420064
that meet the requirements for configuration class implementations as specified in the
2006520065
`@Configuration` javadocs. In the following example, the `OrderServiceTest` class
20066-
declares a static inner configuration class named `Config` that will be automatically
20066+
declares a `static` nested configuration class named `Config` that will be automatically
2006720067
used to load the `ApplicationContext` for the test class. Note that the name of the
2006820068
configuration class is arbitrary. In addition, a test class can contain more than one
20069-
static inner configuration class if desired.
20069+
`static` nested configuration class if desired.
2007020070

2007120071
[source,java,indent=0]
2007220072
[subs="verbatim,quotes"]
2007320073
----
2007420074
@RunWith(SpringJUnit4ClassRunner.class)
2007520075
// ApplicationContext will be loaded from the
20076-
// static inner Config class
20076+
// static nested Config class
2007720077
**@ContextConfiguration**
2007820078
public class OrderServiceTest {
2007920079

@@ -25092,7 +25092,7 @@ Querying and populating a number of domain objects:
2509225092

2509325093
If the last two snippets of code actually existed in the same application, it would make
2509425094
sense to remove the duplication present in the two `RowMapper` anonymous inner classes,
25095-
and extract them out into a single class (typically a `static` inner class) that can
25095+
and extract them out into a single class (typically a `static` nested class) that can
2509625096
then be referenced by DAO methods as needed. For example, it may be better to write the
2509725097
last code snippet as follows:
2509825098

0 commit comments

Comments
 (0)