![JAR search and dependency download from the Maven repository](/logo.png)
io.github.freya022.botcommands.internal.components.builder.BuilderInstanceHolderImpl.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of BotCommands Show documentation
Show all versions of BotCommands Show documentation
A Kotlin-first (and Java) framework that makes creating Discord bots a piece of cake, using the JDA library.
package io.github.freya022.botcommands.internal.components.builder
import io.github.freya022.botcommands.api.components.builder.BuilderInstanceHolder
/**
* Since the instances must be returned to provide a builder-like experience for JVM users,
* we need to get the instance from the implementation itself
*
* However, overriding the [instance] property on the implementation does not allow delegates to access it,
* as the delegates are in their own world.
*
* Kotlin does not support `this` in super constructors or in delegates,
* even though this should be possible by just looking at the decompiled java code
*
* To work around this, we introduce [InstanceRetriever], which will hold our instance,
* and will only be filled in the implementation's constructor, and so, the instance will be available post-construct.
*/
internal sealed class BuilderInstanceHolderImpl> : BuilderInstanceHolder {
protected abstract val instanceRetriever: InstanceRetriever
override val instance: T
get() = instanceRetriever.instance
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy