Yossi Saiada
05/07/2019, 8:24 PMenum class EnumA {
A, B;
val group = EnumB.values().find { this == it.enumA }
}
enum class EnumB(val enumA: EnumA) {
A1(EnumA.A),
B1(EnumA.B),
}
EnumB.values().map { it.enumA } // => [null, null]
EnumA.A.group // == null
EnumB.values().find { EnumA.A == it.enumA } // == null
Why does EnumB.enumA, for every EnumB value, equals null?
(I know it's happening because of the circular dependency (caused by the group property), but I'm not sure it should be like that)
Edit:
I'm a bit confused. I had thought the reason is the circular dependency, but this code:
enum class EnumA(val enumB: EnumB) { A(EnumB.B) }
enum class EnumB(val enumA: EnumA) { B(EnumA.A) }
EnumB.values().map { it.enumA }
actually works as expected and return [A]. 🤨Alexey Belkov [JB]
05/14/2019, 9:41 AM