Classes and Interfaces

Spring Framework 支持各种 Kotlin 构造,例如通过主构造函数实例化 Kotlin 类、不可变类数据绑定以及带有默认值的可选函数参数。

The Spring Framework supports various Kotlin constructs, such as instantiating Kotlin classes through primary constructors, immutable classes data binding, and function optional parameters with default values.

Kotlin 参数名称通过专用的 KotlinReflectionParameterNameDiscoverer 识别,它允许查找接口方法参数名称,而无需在编译期间启用 Java 8 -parameters 编译器标志。(为完整起见,我们仍然建议使用 -java-parameters 标志运行 Kotlin 编译器,以获得标准的 Java 参数显示。)

Kotlin parameter names are recognized through a dedicated KotlinReflectionParameterNameDiscoverer, which allows finding interface method parameter names without requiring the Java 8 -parameters compiler flag to be enabled during compilation. (For completeness, we nevertheless recommend running the Kotlin compiler with its -java-parameters flag for standard Java parameter exposure.)

您可以将配置类声明为 顶层或嵌套而不是内部,因为后者需要对外部类的引用。

You can declare configuration classes as top level or nested but not inner, since the later requires a reference to the outer class.