Skip to content

Instantly share code, notes, and snippets.

View beer-avalanche's full-sized avatar

beer-avalanche

View GitHub Profile
inline fun <reified K : Any> summon(): K {
val tpe = typeOf<K>()
return summon(tpe) as? K
?: error("Trait instance must be of type $tpe")
}
// FIXME: Come up with a way to make it sufficiently weak to prevent
// memory leaks due to accumulation of the underlying classes
// if class loaders are being closed.
private val instances = ConcurrentHashMap<KType, Any>()