You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/main/asciidoc/object-mapping.adoc
+10-8Lines changed: 10 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -228,16 +228,16 @@ Spring Data adapts specifics of Kotlin to allow object creation and mutation.
228
228
Kotlin classes are supported to be instantiated , all classes are immutable by default and require explicit property declarations to define mutable properties. Consider the following `data` class `Person`:
229
229
230
230
====
231
-
[source,java]
231
+
[source,kotlin]
232
232
----
233
233
data class Person(val id: String, val name: String)
234
234
----
235
235
====
236
236
237
-
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:
237
+
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:
238
238
239
239
====
240
-
[source,java]
240
+
[source,kotlin]
241
241
----
242
242
data class Person(var id: String, val name: String) {
243
243
@@ -248,10 +248,10 @@ data class Person(var id: String, val name: String) {
248
248
====
249
249
250
250
Kotlin supports parameter optionality by allowing default values to be used if a parameter is not provided.
251
-
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`
251
+
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`
252
252
253
253
====
254
-
[source,java]
254
+
[source,kotlin]
255
255
----
256
256
data class Person(var id: String, val name: String = "unknown")
257
257
----
@@ -261,13 +261,15 @@ Every time the `name` parameter is either not part of the result or its value is
261
261
262
262
=== Property population of Kotlin data classes
263
263
264
-
In Kotlin, all classes are immutable by default and require explicit property declarations to define mutable properties. Consider the following `data` class `Person`:
264
+
In Kotlin, all classes are immutable by default and require explicit property declarations to define mutable properties.
265
+
Consider the following `data` class `Person`:
265
266
266
267
====
267
-
[source,java]
268
+
[source,kotlin]
268
269
----
269
270
data class Person(val id: String, val name: String)
270
271
----
271
272
====
272
273
273
-
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.
274
+
This class is effectively immutable.
275
+
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.
0 commit comments