https://kotlinlang.org logo
#announcements
Title
# announcements
s

supaham

08/30/2017, 3:48 PM
I have the following code:
Copy code
data class SquadEntry(
        val name: String,
        var leader: OptionalPresence<UUID> = OptionalPresence.empty(),
        var color: OptionalPresence<String> = OptionalPresence.empty(),
        var tag: OptionalPresence<String> = OptionalPresence.empty(),
        var members: OptionalPresence<Set<UUID>>
)
Every time I want to write to a field e.g. leader I have to do leader = OptionalPresence(value). Is there a way to use something like delegate properties to simplify this process?
v

villela

08/30/2017, 10:36 PM
Delegate doesnt let you set a different type than the field
but even if it allowed you would lose the 3 states you are trying to track
or nor.. if you could create 2 different setters, onr for thr primitive associated with OptionalPresence and other for OptionalPresence
you should rethink the way your dao handle things
2 Views