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

linear

03/20/2017, 10:29 PM
I'm trying to create a HashMap that aggregates a bunch of objects, and these objects use the init blocks to register themselves by adding themselves into the HashMap. Unfortunately, it appears to me that Kotlin is thinking that since I never access the objects directly (by name) that they should never initialize, which leaves my HashMap empty
g

groostav

03/20/2017, 10:30 PM
care to post some code? maybe make a [gist](https://gist.github.com/) or code snippit?
l

linear

03/20/2017, 10:30 PM
sure, give me a sec
@Serializes(Sign::class) internal object SignSerializer : BlockStateSerializer() { init { val annotation = javaClass.getAnnotation(Serializes::class.java) ?: throw IllegalStateException("Child class ${javaClass.simpleName} not annotated with @Serializes!") val blockSerializer = this as? InPlaceSerializer<BlockState> ?: throw IllegalStateException("Child class ${javaClass.simpleName} serializes non-block type.") serializersByType.put(annotation.type, blockSerializer) }
can't seem to create Snippet... that functionality does not appear to be exposed in Slack in comment replies =/
15 Views