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
This commit is contained in:
parent
1c6bab23ea
commit
77b7e49fb2
|
@ -75,4 +75,7 @@ public class TestObject implements ITestObject, ITestInterface, Comparable<Objec
|
|||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
public static class NestedObject {
|
||||
}
|
||||
}
|
||||
|
|
|
@ -86,6 +86,8 @@ class ClassUtilsTests {
|
|||
assertThat(ClassUtils.forName("org.springframework.tests.sample.objects.TestObject[][]", classLoader)).isEqualTo(TestObject[][].class);
|
||||
assertThat(ClassUtils.forName(TestObject[][].class.getName(), classLoader)).isEqualTo(TestObject[][].class);
|
||||
assertThat(ClassUtils.forName("[[[S", classLoader)).isEqualTo(short[][][].class);
|
||||
assertThat(ClassUtils.forName("org.springframework.tests.sample.objects.TestObject$NestedObject", classLoader)).isEqualTo(TestObject.NestedObject.class);
|
||||
assertThat(ClassUtils.forName("org.springframework.tests.sample.objects.TestObject.NestedObject", classLoader)).isEqualTo(TestObject.NestedObject.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
@ -641,15 +641,13 @@ You can use the `Class` property in one of two ways:
|
|||
|
||||
****
|
||||
.Inner class names
|
||||
If you want to configure a bean definition for a `static` nested class, you have to use
|
||||
the binary name of the nested class.
|
||||
If you want to configure a bean definition for a `static` nested class, you may use
|
||||
either binary name of the nested class or separate it with dot.
|
||||
|
||||
For example, if you have a class called `SomeThing` in the `com.example` package, and this
|
||||
`SomeThing` class has a `static` nested class called `OtherThing`, the value of the `class`
|
||||
attribute on a bean definition would be `com.example.SomeThing$OtherThing`.
|
||||
|
||||
Notice the use of the `$` character in the name to separate the nested class name from
|
||||
the outer class name.
|
||||
`SomeThing` class has a `static` nested class called `OtherThing`, they can be separated
|
||||
by a dollar (`$`) or dot (`.`). So the value of the `class` attribute on a bean definition
|
||||
would be `com.example.SomeThing$OtherThing` or `com.example.SomeThing.OtherThing`.
|
||||
****
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue