在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):bennyhuo/KotlinDeepCopy开源软件地址(OpenSource Url):https://github.com/bennyhuo/KotlinDeepCopy开源编程语言(OpenSource Language):Kotlin 98.8%开源软件介绍(OpenSource Introduction):KotlinDeepCopyProvide an easy way to generate ReflectionUse Kotlin Reflection to provide an extension function for See the test code below: data class Speaker(val name: String, val age: Int): DeepCopyable
data class Talk(val name: String, val speaker: Speaker): DeepCopyable
class DeepCopyTest {
@Test
fun test() {
val talk = Talk("DataClass in Action", Speaker("Benny Huo", 30))
val newTalk = talk.deepCopy()
assert(talk == newTalk)
assert(talk !== newTalk)
}
}
How to SetupThis library has been deloyed to maven center. implementation("com.bennyhuo.kotlin:deepcopy-reflect:1.5.31.0") Apt & KspIf you concern about the runtime efficiency, apt may be the solution. You can simply annotate the data class you want to deep copy with a @DeepCopy
data class Speaker(val name: String, val age: Int)
@DeepCopy
data class Talk(val name: String, val speaker: Speaker) Extension function fun Talk.deepCopy(name: String = this.name, speaker: Speaker = this.speaker): Talk = Talk(name, speaker.deepCopy())
fun Speaker.deepCopy(
name: String = this.name,
age: Int = this.age,
company: Company = this.company
): Speaker = Speaker(name, age, company.deepCopy()) Notice that fun Talk.deepCopy(name: String = this.name, speaker: Speaker = this.speaker): Talk = Talk(name, speaker)
//And no deepCopy for Speaker. How to SetupThe artifacts have been deployed to maven central repository. Set up your project by adding these lines: plugins {
id("com.google.devtools.ksp") version "1.5.31-1.0.1" // ksp
id "org.jetbrains.kotlin.kapt" // kapt
}
...
dependencies {
ksp("com.bennyhuo.kotlin:deepcopy-compiler-ksp:1.5.31.0")) // ksp
kapt("com.bennyhuo.kotlin:deepcopy-compiler-kapt:1.5.31.0") // kapt
implementation("com.bennyhuo.kotlin:deepcopy-runtime:1.5.31.0")
} Change Logv1.5.31.0 Reflect & Apt & Ksp
v1.5.0 Reflect & AptCompiles on Kotlin v1.5.0. Update v1.3.72 AptCompiles on Kotlin v1.3.72.
v1.3.0 Apt
v1.2.0 Apt
v1.1.0 Apt
License
|
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论