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

Fin

08/28/2019, 6:36 AM
Is there any easier way in Kotlin to achieve that mapping to state variables without repeating myself over and over again? Can I make my State attributes somehow directly accessible in main Class?
s

Sebastian Sellmair [JB]

08/28/2019, 6:42 AM
Is state a class or interface?
a

Alowaniak

08/28/2019, 6:42 AM
Well if there's an interface with only the id then you could use delegate by
or I mean an interface with the attributes you want to expose
s

Sebastian Sellmair [JB]

08/28/2019, 6:43 AM
If you define the properties of
State
in some interface, then you could declare it like
Copy code
class Blub(state: State): State by state
f

Fin

08/28/2019, 6:52 AM
Since it’s about 30 attributes, I guess delegate by will get too much boilercode. Introducing an interface would be easier, let me give a try. Thank you guys !
b

bbaldino

08/28/2019, 5:43 PM
what about storing the properties in a map and delegating to that? https://kotlinlang.org/docs/reference/delegated-properties.html#storing-properties-in-a-map
if
State
could implement Map, maybe
2 Views