Skip to content
This repository was archived by the owner on Jan 20, 2023. It is now read-only.

Commit 634dc01

Browse files
committed
Initialization from KClass
1 parent 6dbd08c commit 634dc01

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

README.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,45 @@ The following three methods are the main ways to get the `method reference`.
121121
- from `factory method` in `companion object`: `(Dst)::factoryMethod`
122122
- from instance method in `this` scope: `this::factoryMethod`
123123

124+
### Initialization from KClass
125+
The `KRowMapper` can be initialized by `KClass`.
126+
By default, the primary constructor is the target of the call.
127+
128+
```kotlin
129+
data class Dst(...)
130+
131+
val mapper: KRowMapper<Dst> = KRowMapper(Dst::class)
132+
```
133+
134+
#### Specifying the target of a call by KConstructor annotation
135+
When you initialize from the `KClass`, you can use the `KConstructor` annotation and to specify the function to be called.
136+
137+
In the following example, the `secondary constructor` is called.
138+
139+
```kotlin
140+
data class Dst(...) {
141+
@KConstructor
142+
constructor(...) : this(...)
143+
}
144+
145+
val mapper: KRowMapper<Dst> = KRowMapper(Dst::class)
146+
```
147+
148+
Similarly, the following example calls the `factory method`.
149+
150+
```kotlin
151+
data class Dst(...) {
152+
companion object {
153+
@KConstructor
154+
fun factory(...): Dst {
155+
...
156+
}
157+
}
158+
}
159+
160+
val mapper: KRowMapper<Dst> = KRowMapper(Dst::class)
161+
```
162+
124163
## Usage
125164
### Deserialize column
126165
`KRowMapper` provides a deserialization function for the acquisition results of three patterns.

0 commit comments

Comments
 (0)