Skip to content

Commit 067ad4c

Browse files
committed
Update Kotlin reference documentation
1 parent 52dfc4e commit 067ad4c

File tree

1 file changed

+30
-31
lines changed

1 file changed

+30
-31
lines changed

src/docs/asciidoc/languages/kotlin.adoc

+30-31
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ existing libraries written in Java.
99
The Spring Framework provides first-class support for Kotlin that allows developers to write
1010
Kotlin applications almost as if the Spring Framework was a native Kotlin framework.
1111

12+
Feel free to join the #spring channel of http://slack.kotlinlang.org/[Kotlin Slack] or ask
13+
a question with `spring` and `kotlin` tags on
14+
https://stackoverflow.com/questions/tagged/spring+kotlin[Stackoverflow] if you need support.
1215

1316

1417

@@ -17,8 +20,8 @@ Kotlin applications almost as if the Spring Framework was a native Kotlin framew
1720

1821
Spring Framework supports Kotlin 1.1+ and requires
1922
https://bintray.com/bintray/jcenter/org.jetbrains.kotlin%3Akotlin-stdlib[`kotlin-stdlib`]
20-
(or one of its https://bintray.com/bintray/jcenter/org.jetbrains.kotlin%3Akotlin-stdlib-jre7[`kotlin-stdlib-jre7`]
21-
/ https://bintray.com/bintray/jcenter/org.jetbrains.kotlin%3Akotlin-stdlib-jre8[`kotlin-stdlib-jre8`] variants)
23+
(or one of its variants like https://bintray.com/bintray/jcenter/org.jetbrains.kotlin%3Akotlin-stdlib-jre8[`kotlin-stdlib-jre8`]
24+
for Kotlin 1.1 or https://bintray.com/bintray/jcenter/org.jetbrains.kotlin%3Akotlin-stdlib-jdk8[`kotlin-stdlib-jdk8`] for Kotlin 1.2+)
2225
and https://bintray.com/bintray/jcenter/org.jetbrains.kotlin%3Akotlin-reflect[`kotlin-reflect`]
2326
to be present on the classpath. They are provided by default if one bootstraps a Kotlin project on
2427
https://start.spring.io/#!language=kotlin[start.spring.io].
@@ -94,7 +97,7 @@ via tooling-friendly annotations declared in the `org.springframework.lang` pack
9497
By default, types from Java APIs used in Kotlin are recognized as
9598
https://kotlinlang.org/docs/reference/java-interop.html#null-safety-and-platform-types[platform types]
9699
for which null-checks are relaxed.
97-
https://github.com/Kotlin/KEEP/blob/jsr-305/proposals/jsr-305-custom-nullability-qualifiers.md[Kotlin support for JSR 305 annotations]
100+
https://kotlinlang.org/docs/reference/java-interop.html#jsr-305-support[Kotlin support for JSR 305 annotations]
98101
+ Spring nullability annotations provide null-safety for the whole Spring Framework API to Kotlin developers,
99102
with the advantage of dealing with `null` related issues at compile time.
100103

@@ -106,15 +109,16 @@ Libraries like Reactor or Spring Data provide null-safe APIs leveraging this fea
106109
The JSR 305 checks can be configured by adding the `-Xjsr305` compiler flag with the following
107110
options: `-Xjsr305={strict|warn|ignore}`.
108111

109-
For kotlin versions 1.1.50+, the default behavior is the same to `-Xjsr305=warn`.
110-
The `strict` value is required to have Spring Framework API full null-safety taken in account
111-
but should be considered experimental since Spring API nullability declaration could evolve
112-
even between minor releases and more checks may be added in the future).
112+
For kotlin versions 1.1+, the default behavior is the same to `-Xjsr305=warn`.
113+
The `strict` value is required to have Spring Framework API null-safety taken in account
114+
in Kotlin types inferred from Spring API but should be used with the knowledge that Spring
115+
API nullability declaration could evolve even between minor releases and more checks may
116+
be added in the future).
113117

114118
[NOTE]
115119
====
116120
Generic type arguments, varargs and array elements nullability are not supported yet,
117-
but should be in an upcoming release, see https://github.com/Kotlin/KEEP/issues/79[this dicussion]
121+
but should be in an upcoming release, see https://github.com/Kotlin/KEEP/issues/79[this discussion]
118122
for up-to-date information.
119123
====
120124

@@ -523,8 +527,8 @@ can be customised with configuration beans, like as follows:
523527
====
524528
If Spring Boot is being used, then
525529
https://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-external-config.html#boot-features-external-config-typesafe-configuration-properties[`@ConfigurationProperties`]
526-
instead of `@Value` annotations can be used, but currently this only works with nullable `var`
527-
properties (which is far from ideal) since immutable classes initialized by
530+
instead of `@Value` annotations can be used, but currently this only works with `lateinit` or nullable `var`
531+
properties (the former is recommended) since immutable classes initialized by
528532
constructors are not yet supported.
529533
See these issues about https://github.com/spring-projects/spring-boot/issues/8762[`@ConfigurationProperties` binding for immutable POJOs]
530534
and https://github.com/spring-projects/spring-boot/issues/1254[`@ConfigurationProperties` binding on interfaces]
@@ -536,9 +540,10 @@ for more details.
536540
=== Annotation array attributes
537541

538542
Kotlin annotations are mostly similar to Java ones, but array attributes - which are
539-
extensively used in Spring - behave differently. As explained in https://kotlinlang.org/docs/reference/annotations.html[Kotlin documentation]
540-
unlike other attributes, the `value` attribute name can be omitted and when it is an array
541-
attribute it is specified as a `vararg` parameter.
543+
extensively used in Spring - behave differently. As explained in
544+
https://kotlinlang.org/docs/reference/annotations.html[Kotlin documentation]
545+
unlike other attributes, the `value` attribute name can be omitted and
546+
specified as a `vararg` parameter.
542547

543548
To understand what that means, let's take `@RequestMapping`, which is one
544549
of the most widely used Spring annotations as an example. This Java annotation is declared as:
@@ -567,23 +572,19 @@ That's why one can write
567572
`@RequestMapping(value = "/foo", method = RequestMethod.GET)` or
568573
`@RequestMapping(path = "/foo", method = RequestMethod.GET)`.
569574

570-
However, in Kotlin, one will have to write `@RequestMapping("/foo", method = arrayOf(RequestMethod.GET))`.
571-
The variant using `path` is not recommended as it need to be written
572-
`@RequestMapping(path = arrayOf("/foo"), method = arrayOf(RequestMethod.GET))`.
575+
However, in Kotlin 1.2+, one will have to write `@RequestMapping("/foo", method = [RequestMethod.GET])`
576+
or `@RequestMapping(path = ["/foo"], method = [RequestMethod.GET])` (square brackets need
577+
to be specified with named array attributes).
573578

574-
A workaround for this specific `method` attribute (the most common one) is to
579+
An alternative for this specific `method` attribute (the most common one) is to
575580
use a shortcut annotation such as `@GetMapping` or `@PostMapping`, etc.
576581

577582
[NOTE]
578583
====
579584
Reminder: If the `@RequestMapping` `method` attribute is not specified,
580-
all HTTP methods will be matched, not only the `GET` methods.
585+
all HTTP methods will be matched, not only the `GET` one.
581586
====
582587

583-
Improving the syntax and consistency of Kotlin annotation array attributes is discussed in
584-
https://youtrack.jetbrains.com/issue/KT-11235[this Kotlin language design issue].
585-
586-
587588

588589
=== Testing
589590

@@ -702,11 +703,12 @@ MVC and its annotation-based programming model is a perfectly valid and fully su
702703

703704

704705

705-
[[kotlin-resources-started]]
706+
[[kotlin-resources]]
706707
== Resources
707708

708709
* http://kotlinlang.org/docs/reference/[Kotlin language reference]
709710
* http://slack.kotlinlang.org/[Kotlin Slack] (with a dedicated #spring channel)
711+
* https://stackoverflow.com/questions/tagged/spring+kotlin[Stackoverflow with `spring` and `kotlin` tags]
710712
* https://try.kotlinlang.org/[Try Kotlin in your browser]
711713
* https://blog.jetbrains.com/kotlin/[Kotlin blog]
712714
* https://kotlin.link/[Awesome Kotlin]
@@ -729,6 +731,7 @@ MVC and its annotation-based programming model is a perfectly valid and fully su
729731
* https://github.com/sdeleuze/spring-kotlin-functional[spring-kotlin-functional]: standalone WebFlux + functional bean definition DSL
730732
* https://github.com/sdeleuze/spring-kotlin-fullstack[spring-kotlin-fullstack]: WebFlux Kotlin fullstack example with Kotlin2js for frontend instead of JavaScript or TypeScript
731733
* https://github.com/spring-petclinic/spring-petclinic-kotlin[spring-petclinic-kotlin]: Kotlin version of the Spring PetClinic Sample Application
734+
* https://github.com/sdeleuze/spring-kotlin-deepdive[spring-kotlin-deepdive]: a step by step migration for Boot 1.0 + Java to Boot 2.0 + Kotlin
732735

733736

734737

@@ -752,26 +755,22 @@ Here is a list of pending issues related to Spring + Kotlin support.
752755

753756
==== Spring Boot
754757

755-
* https://github.com/spring-projects/spring-boot/issues/5537[Improve Kotlin support]
756758
* https://github.com/spring-projects/spring-boot/issues/8762[Allow `@ConfigurationProperties` binding for immutable POJOs]
757759
* https://github.com/spring-projects/spring-boot/issues/1254[Allow `@ConfigurationProperties` binding on interfaces]
758-
* https://github.com/spring-projects/spring-boot/issues/8511[Provide support for Kotlin KClass parameter in `SpringApplication.run()`]
759760
* https://github.com/spring-projects/spring-boot/issues/8115[Expose the functional bean registration API via `SpringApplication`]
761+
* https://github.com/spring-projects/spring-boot/issues/10712[Add null-safety annotations on Spring Boot APIs]
762+
* https://github.com/spring-projects/spring-boot/issues/9486[Use Kotlin's bom to provide dependency management for Kotlin]
760763

761764

762765
==== Kotlin
763766

764-
* https://github.com/Kotlin/KEEP/issues/79[Better generics null-safety support]
765767
* https://youtrack.jetbrains.com/issue/KT-6380[Parent issue for Spring Framework support]
768+
* https://youtrack.jetbrains.com/issue/KT-5464[Kotlin requires type inference where Java doesn't]
769+
* https://github.com/Kotlin/KEEP/issues/79[Better generics null-safety support]
766770
* https://youtrack.jetbrains.com/issue/KT-20283[Smart cast regression with open classes]
767771
* https://youtrack.jetbrains.com/issue/KT-18833[JSR-223 application classpath not available when using Java 9]
768-
* https://youtrack.jetbrains.com/issue/KT-15667[Support "::foo" as a short-hand syntax for bound callable reference to "this::foo"]
769-
* https://youtrack.jetbrains.com/issue/KT-11235[Allow specifying array annotation attribute single value without arrayOf()]
770-
* https://youtrack.jetbrains.com/issue/KT-5464[Kotlin requires type inference where Java doesn't]
771772
* https://youtrack.jetbrains.com/issue/KT-14984[Impossible to pass not all SAM argument as function]
772773
* https://youtrack.jetbrains.com/issue/KT-19592[Apply JSR 305 meta-annotations to generic type parameters]
773774
* https://youtrack.jetbrains.com/issue/KT-18398[Provide a way for libraries to avoid mixing Kotlin 1.0 and 1.1 dependencies]
774775
* https://youtrack.jetbrains.com/issue/KT-15125[Support JSR 223 bindings directly via script variables]
775-
* https://youtrack.jetbrains.com/issue/KT-16780[Kotlin Runtime library warning with kotlin-script-util dependency]
776-
* https://youtrack.jetbrains.com/issue/KT-18765[Move incremental compilation message from Gradle's warning to info logging level]
777776
* https://youtrack.jetbrains.com/issue/KT-15467[Support all-open and no-arg compiler plugins in Kotlin Eclipse plugin]

0 commit comments

Comments
 (0)