Skip to content

Commit 77b7e49

Browse files
alex-kravsbrannen
authored andcommitted
Update ref docs for Inner class names
This commit updates the reference manual to point out that one may use `.` instead of `$` as the nested class separator when providing a fully qualified class name for a nested class in XML configuration. This commit also updates the test for ClassUtils#forName to assert support for `.` instead of `$`. Closes gh-26540
1 parent 1c6bab2 commit 77b7e49

File tree

3 files changed

+10
-7
lines changed

3 files changed

+10
-7
lines changed

spring-core/src/test/java/org/springframework/tests/sample/objects/TestObject.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,4 +75,7 @@ public int compareTo(Object o) {
7575
return 1;
7676
}
7777
}
78+
79+
public static class NestedObject {
80+
}
7881
}

spring-core/src/test/java/org/springframework/util/ClassUtilsTests.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,8 @@ void forName() throws ClassNotFoundException {
8686
assertThat(ClassUtils.forName("org.springframework.tests.sample.objects.TestObject[][]", classLoader)).isEqualTo(TestObject[][].class);
8787
assertThat(ClassUtils.forName(TestObject[][].class.getName(), classLoader)).isEqualTo(TestObject[][].class);
8888
assertThat(ClassUtils.forName("[[[S", classLoader)).isEqualTo(short[][][].class);
89+
assertThat(ClassUtils.forName("org.springframework.tests.sample.objects.TestObject$NestedObject", classLoader)).isEqualTo(TestObject.NestedObject.class);
90+
assertThat(ClassUtils.forName("org.springframework.tests.sample.objects.TestObject.NestedObject", classLoader)).isEqualTo(TestObject.NestedObject.class);
8991
}
9092

9193
@Test

src/docs/asciidoc/core/core-beans.adoc

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -641,15 +641,13 @@ You can use the `Class` property in one of two ways:
641641

642642
****
643643
.Inner class names
644-
If you want to configure a bean definition for a `static` nested class, you have to use
645-
the binary name of the nested class.
644+
If you want to configure a bean definition for a `static` nested class, you may use
645+
either binary name of the nested class or separate it with dot.
646646
647647
For example, if you have a class called `SomeThing` in the `com.example` package, and this
648-
`SomeThing` class has a `static` nested class called `OtherThing`, the value of the `class`
649-
attribute on a bean definition would be `com.example.SomeThing$OtherThing`.
650-
651-
Notice the use of the `$` character in the name to separate the nested class name from
652-
the outer class name.
648+
`SomeThing` class has a `static` nested class called `OtherThing`, they can be separated
649+
by a dollar (`$`) or dot (`.`). So the value of the `class` attribute on a bean definition
650+
would be `com.example.SomeThing$OtherThing` or `com.example.SomeThing.OtherThing`.
653651
****
654652

655653

0 commit comments

Comments
 (0)