diff --git a/src/main/asciidoc/object-mapping.adoc b/src/main/asciidoc/object-mapping.adoc index d8e3c6bc2..1adecf696 100644 --- a/src/main/asciidoc/object-mapping.adoc +++ b/src/main/asciidoc/object-mapping.adoc @@ -232,16 +232,16 @@ Kotlin classes are supported to be instantiated , all classes are immutable by d Consider the following `data` class `Person`: ==== -[source,java] +[source,kotlin] ---- data class Person(val id: String, val name: String) ---- ==== -The class above compiles to a typical class with an explicit constructor. We can customize this class by adding another constructor and annotate it with `@PersistenceConstructor` to indicate a constructor preference: +The class above compiles to a typical class with an explicit constructor.We can customize this class by adding another constructor and annotate it with `@PersistenceConstructor` to indicate a constructor preference: ==== -[source,java] +[source,kotlin] ---- data class Person(var id: String, val name: String) { @@ -252,10 +252,10 @@ data class Person(var id: String, val name: String) { ==== Kotlin supports parameter optionality by allowing default values to be used if a parameter is not provided. -When Spring Data detects a constructor with parameter defaulting, then it leaves these parameters absent if the data store does not provide a value (or simply returns `null`) so Kotlin can apply parameter defaulting. Consider the following class that applies parameter defaulting for `name` +When Spring Data detects a constructor with parameter defaulting, then it leaves these parameters absent if the data store does not provide a value (or simply returns `null`) so Kotlin can apply parameter defaulting.Consider the following class that applies parameter defaulting for `name` ==== -[source,java] +[source,kotlin] ---- data class Person(var id: String, val name: String = "unknown") ---- @@ -265,13 +265,15 @@ Every time the `name` parameter is either not part of the result or its value is === Property population of Kotlin data classes -In Kotlin, all classes are immutable by default and require explicit property declarations to define mutable properties. Consider the following `data` class `Person`: +In Kotlin, all classes are immutable by default and require explicit property declarations to define mutable properties. +Consider the following `data` class `Person`: ==== -[source,java] +[source,kotlin] ---- data class Person(val id: String, val name: String) ---- ==== -This class is effectively immutable. It allows to create new instances as Kotlin generates a `copy(…)` method that creates new object instances copying all property values from the existing object and applying property values provided as arguments to the method. +This class is effectively immutable. +It allows creating new instances as Kotlin generates a `copy(…)` method that creates new object instances copying all property values from the existing object and applying property values provided as arguments to the method.