I have three enum class with init block in companion object. All of them have the same method like XXX.register()
@Test
fun aTest(){
val objectMapper = ObjectMapper()
val readValue: InterfaceA = objectMapper.readValue(jsonString, InterfaceA::class.java)
MatcherAssert.assertThat(readValue.XXXType,Is.`is`(InterfaceA.EnumA.SomeInstance))
}
enum class A: InterfaceA{
companion object {
init {
InterfaceA.register(enumA.values())
}
}
InterfaceA{
companion object {
private val subClassRegisterCache :MutableMap<String, InterfaceA> = mutableMapOf()
fun <T:InterfaceA> register(array: Array<T>){
array.map { subClassRegisterCache.put(it.getName(),it)
}
}
}
But when I run a test case in debug mode, it shows running order like
- enumB.init
- testcase
- enumA.init
- enumC.init
In my mind, the order should be like
- any enum.init
- any rest enum.init
- last enum.init
- testcase
Any idea?