aeruhxi
02/14/2018, 7:15 AMdata class Post(
val id: String,
val content: String,
val timestamp: Long,
val photos: List<String>
) : Model()
data class FullPost(
val id: String,
val content: String,
val timestamp: Long,
val photos: List<String>,
val postedBy: User,
val with: List<User>,
val checkedIn: Restaurant,
val actType: String,
val likesCount: Int
) : Model()
Is there a better way to copy the fields of Post to FullPost? So that I don't have to repeat fields like thisCzar
02/14/2018, 7:25 AMOlekss
02/14/2018, 7:25 AMCzar
02/14/2018, 7:28 AMaeruhxi
02/14/2018, 7:37 AMmzgreen
02/14/2018, 7:40 AMFullPost
to extend Post
?aeruhxi
02/14/2018, 7:41 AMmzgreen
02/14/2018, 7:46 AMModel
to be a sealed class
and move common fields there?hallvard
02/14/2018, 7:48 AMdata class FullPost(val basisPost: Post
val postedBy: User,
val with: List<User>,
val checkedIn: Restaurant,
val actType: String,
val likesCount: Int
) : Model()
aeruhxi
02/14/2018, 7:49 AMModel
. So can't really do that @mzgreenCzar
02/14/2018, 7:53 AMAny annotation based library for this that plays well with data class?You don't need annotations, seems pretty simple case. You could use something like Apache commons-beanutils
aeruhxi
02/14/2018, 8:00 AMcopyProperties
works on objects. I want it on classes.
What I have in mind is something like
data class Post(
val id: String,
val content: String,
val timestamp: Long,
val photos: List<String>
) : Model()
@CopyProperties(Post::class)
data class FullPost(
val postedBy: User,
val with: List<User>,
val checkedIn: Restaurant,
val actType: String,
val likesCount: Int
) : Model()
Czar
02/14/2018, 8:04 AMaeruhxi
02/14/2018, 8:12 AMmarstran
02/14/2018, 8:36 AMbasisPost
parameter in @hallvard's solution. It works only if Model
is an interface though. Like this:
data class FullPost(val basisPost: Post
val postedBy: User,
val with: List<User>,
val checkedIn: Restaurant,
val actType: String,
val likesCount: Int
) : Model() by basisPost
Andreas Sinz
02/14/2018, 8:38 AM