Skip to content

Avoiding Reflections

JDA-Commands uses java.lang.reflect in two places:

If you want to completely avoid java.lang.reflect you have to provide your own implementations.

ClassFinder

ClassFinders are used to provide instances of Class that will be scanned for interactions or custom implementations. You can register at the JDA-Commands Builder.

JDACommands.builder(jda, Main.class)
    .classFinders(new CustomClassFinder())
    .start();

Use ClassFinder#explicit(Class...) if you want to explicitly add a Class.

Warning

Calling classFinders(Class...) on the builder will override existing class finders. If you want to keep the default reflective class finder, you have to add it again via ClassFinder#reflective(String...).

JDACommands.builder(jda, Main.class)
    .classFinders(ClassFinder.explicit(ForeignClass.class), ClassFinder.reflective(Main.class, "com.package"))
    .start();

Descriptor

A Descriptor takes a Class as input and transforms it into a ClassDescription. Descriptors can also be registered using the @Implementation annotation. Alternatively, register them at the JDA-Commands Builder.

JDACommands.builder(jda, Main.class)
    .descriptor(new CustomDescriptor());
    .start();

EmojiSource

EmojiSources are used to load application emojis that should be registered automatically upon startup for you. They're similar to ClassFinders.

You can register them at the JDA-Commands Builder or via the @Implementation annotation.

JDACommands.builder(jda, Main.class)
    .emojiSources(new CustomEmojiSource())
    .start();

Warning

Calling emojiSources(...) on the builder will override existing emoji sources. If you want to keep the default reflective emoji source, you have to add it again via EmojiSource#reflective(String...).