¿Usando rasgos con classs de datos en Kotlin?

Tengo dos objects model / DTO definidos como classs de datos

public data class ModelA(val limit: Int, val offset: Int, val someDataA: DataAlpha) public data class ModelB(val limit: Int, val offset: Int, val someDataB: DataBeta) 

Me gustaría generalizar la pagination basada en algo como el rasgo de Paginable :

 trait Paginable { var limit: Int var offset: Int } 

Pero hacer que ModelA implemente Paginable provoca un error:

Error: 'offset' oculta el miembro del supertipo 'Paginable' y necesita el modificador 'anular'

Agregar anulación :

 public data class ModelB(override val limit: Int, override val offset: Int, val someDataB: DataBeta) : Paginable 

causa un error aún más interesante, rompiendo el comstackdor:

 Error:java.lang.ClassCastException: org.jetbrains.kotlin.psi.JetParameter cannot be cast to org.jetbrains.kotlin.psi.JetProperty at org.jetbrains.kotlin.resolve.OverrideResolver$3.varOverriddenByVal(OverrideResolver.java:562) at org.jetbrains.kotlin.resolve.OverrideResolver.checkOverridesForMemberMarkedOverride(OverrideResolver.java:606) at org.jetbrains.kotlin.resolve.OverrideResolver.checkOverrideForMember(OverrideResolver.java:529) at org.jetbrains.kotlin.resolve.OverrideResolver.checkOverridesInAClass(OverrideResolver.java:269) at org.jetbrains.kotlin.resolve.OverrideResolver.checkOverrides(OverrideResolver.java:260) at org.jetbrains.kotlin.resolve.OverrideResolver.check(OverrideResolver.java:67) at org.jetbrains.kotlin.resolve.LazyTopDownAnalyzer.analyzeDeclarations(LazyTopDownAnalyzer.java:299) at org.jetbrains.kotlin.resolve.LazyTopDownAnalyzerForTopLevel.analyzeDeclarations(LazyTopDownAnalyzerForTopLevel.java:77) at org.jetbrains.kotlin.resolve.LazyTopDownAnalyzerForTopLevel.analyzeFiles(LazyTopDownAnalyzerForTopLevel.java:69) at org.jetbrains.kotlin.resolve.jvm.TopDownAnalyzerFacadeForJVM.analyzeFilesWithJavaIntegration(TopDownAnalyzerFacadeForJVM.java:147) at org.jetbrains.kotlin.resolve.jvm.TopDownAnalyzerFacadeForJVM.analyzeFilesWithJavaIntegrationWithCustomContext(TopDownAnalyzerFacadeForJVM.java:100) at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler$2.invoke(KotlinToJVMBytecodeCompiler.java:307) at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler$2.invoke(KotlinToJVMBytecodeCompiler.java:300) at org.jetbrains.kotlin.cli.common.messages.AnalyzerWithCompilerReport.analyzeAndReport(AnalyzerWithCompilerReport.java:232) at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler.analyze(KotlinToJVMBytecodeCompiler.java:299) at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler.analyzeAndGenerate(KotlinToJVMBytecodeCompiler.java:282) at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler.compileBunchOfSources(KotlinToJVMBytecodeCompiler.java:208) at org.jetbrains.kotlin.cli.jvm.K2JVMCompiler.doExecute(K2JVMCompiler.java:189) at org.jetbrains.kotlin.cli.jvm.K2JVMCompiler.doExecute(K2JVMCompiler.java:49) at org.jetbrains.kotlin.cli.common.CLICompiler.exec(CLICompiler.java:148) at org.jetbrains.kotlin.gradle.tasks.AbstractKotlinCompile.callCompiler(Tasks.kt:86) at org.jetbrains.kotlin.gradle.tasks.AbstractKotlinCompile.compile(Tasks.kt:62) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:483) at org.gradle.internal.reflect.JavaMethod.invoke(JavaMethod.java:63) at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory$StandardTaskAction.doExecute(AnnotationProcessingTaskFactory.java:218) at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory$StandardTaskAction.execute(AnnotationProcessingTaskFactory.java:211) at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory$StandardTaskAction.execute(AnnotationProcessingTaskFactory.java:200) at org.gradle.api.internal.AbstractTask$TaskActionWrapper.execute(AbstractTask.java:579) at org.gradle.api.internal.AbstractTask$TaskActionWrapper.execute(AbstractTask.java:562) at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeAction(ExecuteActionsTaskExecuter.java:80) at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:61) at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.java:46) at org.gradle.api.internal.tasks.execution.PostExecutionAnalysisTaskExecuter.execute(PostExecutionAnalysisTaskExecuter.java:35) at org.gradle.api.internal.tasks.execution.SkipUpToDateTaskExecuter.execute(SkipUpToDateTaskExecuter.java:64) at org.gradle.api.internal.tasks.execution.ValidatingTaskExecuter.execute(ValidatingTaskExecuter.java:58) at org.gradle.api.internal.tasks.execution.SkipEmptySourceFilesTaskExecuter.execute(SkipEmptySourceFilesTaskExecuter.java:42) at org.gradle.api.internal.tasks.execution.SkipTaskWithNoActionsExecuter.execute(SkipTaskWithNoActionsExecuter.java:52) at org.gradle.api.internal.tasks.execution.SkipOnlyIfTaskExecuter.execute(SkipOnlyIfTaskExecuter.java:53) at org.gradle.api.internal.tasks.execution.ExecuteAtMostOnceTaskExecuter.execute(ExecuteAtMostOnceTaskExecuter.java:43) 

Soy consciente de que el rasgo se puede implementar "manualmente" dentro del cuerpo de la class, pero esto romperá la class de datos como equals , hashCode y copy ignorará las properties añadidas.

    Puede corregir su código utilizando el mismo tipo de propiedad ( val / var ) en ambos lados ( trait y data class ).