Browse Source

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
pull/26551/head
Oleksandr Kravchuk 5 years ago committed by Sam Brannen
parent
commit
77b7e49fb2
  1. 3
      spring-core/src/test/java/org/springframework/tests/sample/objects/TestObject.java
  2. 2
      spring-core/src/test/java/org/springframework/util/ClassUtilsTests.java
  3. 12
      src/docs/asciidoc/core/core-beans.adoc

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

@ -75,4 +75,7 @@ public class TestObject implements ITestObject, ITestInterface, Comparable<Objec @@ -75,4 +75,7 @@ public class TestObject implements ITestObject, ITestInterface, Comparable<Objec
return 1;
}
}
public static class NestedObject {
}
}

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

@ -86,6 +86,8 @@ class ClassUtilsTests { @@ -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

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

@ -641,15 +641,13 @@ You can use the `Class` property in one of two ways: @@ -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…
Cancel
Save