angarron
03/06/2017, 9:44 PMdata class
. It's easiest to understand by example. I have something like this contrived example:
data class ManageUserHelper(val canKick: Boolean, val canBan: Boolean)
but I want to have an initialization flow where those booleans are computed:
constructor(val actingUser: User, val targetUser: User, val relationship: Relationship) {
val canKick = // do something complicated w/ users + relationship
val canBan = // do something complicated w/ users + relationship, which may depend on the above
this(canKick, canBan)
}
^ Obviously the above does not compile because the secondary constructor does not immediately delegate to the primary constructor. Until now I have solved this problem by moving that secondary constructor into a buildFrom
method inside of a companion object
but that feels messy to me. Is there a more idiomatic way to accomplish what I want?
Thanks for the help, and again let me know if there is a better place to ask!voddan
03/07/2017, 3:56 AMbuildFrom
in the package alongside the class. That makes the code somewhat cleaner