Michael de Kaste
11/01/2021, 11:24 AMJoffrey
11/01/2021, 11:29 AMyourMap.get(YourEnum.TYPE_1)
) then you could just build a correct instance of the sealed class's subclass right away instead. However, if you're using a dynamic enum value (yourMap.get(someEnumValueVariable)
), you can't know at compile time which type of instance you will get anyway, so there is no real point in enforcing that your map returns the specific subtype anyway. Or did I miss something here?sealed class Original {
data class ActualImpl1(...) : Original()
data class ActualImpl2(...) : Original()
}
// this replaces your enum
sealed class MyKey<T : Original> {
object Type1 : MyKey<ActualImpl1>()
object Type2 : MyKey<ActualImpl2>()
}
This would allow you to build your heterogeneous typesafe map, but at this point I believe it might be better to use the original sealed class instead of the enum in more places šMichael de Kaste
11/01/2021, 11:39 AMclass Workflow{
val someData: String
val someMoreData: String
val type1Information: Information.Type1? = null
val type2Information: Information.Type2? = null
val type3Information: Information.Type3? = null
}
and then on creation we fill the known and desired information and can easily just access all the vals. the problem is that the amount of types in our application is slowly growing as we are implementing more and more for our customers and therefor, having littered values is bloating our code. An EnumMap would provide the perfect solution I would thinkJoffrey
11/01/2021, 2:16 PMthe values are not objects sadly. Per person/worker/registration/etc, per domain, you can have a different version of an implementation meaning that the values of said map are data classes, that are filled upon creation.The `object`s in my suggestion were meant to replace the enum, not the current sealed class hierarchy that you have. The
Original
sealed class in my example would still be there and still have proper classes with data inside. The idea of the second sealed class instead of the enum was to allow a type safe map access you seemed to want.