eu.vendeli.tgbot.core.ClassManagerImpl.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of telegram-bot Show documentation
Show all versions of telegram-bot Show documentation
Telegram Bot API wrapper, with handy Kotlin DSL.
package eu.vendeli.tgbot.core
import eu.vendeli.tgbot.interfaces.ClassManager
/**
* Default [ClassManager] implementation
*
* @constructor Create empty ClassManagerImpl
*/
class ClassManagerImpl : ClassManager {
// keep class instances
private val instances by lazy { mutableMapOf() }
/**
* Get instance of class
*
* @param clazz
* @param initParams
* @return class
*/
override fun getInstance(clazz: Class<*>, vararg initParams: Any?): Any = instances.getOrElse(clazz.name) {
if (initParams.isEmpty()) clazz.declaredConstructors.first().newInstance()
else {
clazz.declaredConstructors.first().newInstance(initParams)
}.also { instances[clazz.name] = it }
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy