Kotlin:如何在非数据类之间复制一些属性?

时间:2018-03-24 18:11:15

标签: kotlin

我是Java中的第三方类,我想从中将一些属性复制到Kotlin非数据类。大多数属性都是直接复制,有些属性是派生的。除了平凡的复制粘贴之外,还有一种聪明的方法吗?我查看了代表,但它不适合我的用例。

Java类是TestExecutionSummary的实现。我对真正的实现类感兴趣,只是接口公开的方法。

我的课程:

@Entity
class TestExecutionSummary {
    @EmbeddedId
    lateinit var id: TestExecutionId

    lateinit var timeStarted: OffsetDateTime
    lateinit var timeFinished: OffsetDateTime
    var totalFailureCount: Long by Delegates.notNull()
    var containersFoundCount: Long by Delegates.notNull()
    var containersStartedCount: Long by Delegates.notNull()
    var containersSkippedCount: Long by Delegates.notNull()
    var containersAbortedCount: Long by Delegates.notNull()
    var containersSucceededCount: Long by Delegates.notNull()
    var containersFailedCount: Long by Delegates.notNull()
    var testsFoundCount: Long by Delegates.notNull()
    var testsStartedCount: Long by Delegates.notNull()
    var testsSkippedCount: Long by Delegates.notNull()
    var testsAbortedCount: Long by Delegates.notNull()
    var testsSucceededCount: Long by Delegates.notNull()
    var testsFailedCount: Long by Delegates.notNull()
    @OneToMany(cascade = [CascadeType.ALL])
    var failures: List<TestFailure> = emptyList()

    @Embeddable
    class TestExecutionId {
        var id: Long by Delegates.notNull()
        var jobExecutionId: Long by Delegates.notNull()
    }
}

0 个答案:

没有答案