Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8867701
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T17:06:22+00:00 2026-06-14T17:06:22+00:00

Sorry about the strange topic name, could not find one that fitted well. To

  • 0

Sorry about the strange topic name, could not find one that fitted well.
To my problem, i want to create something dynamic in Java, it is a very simple class that can take an event and throw it along, sadly have the system i am using be made so each event must have it own method where the event is the argument of the method, but the good news is that we can add as many event listener classes as we want! I wan my program to be able to dynamic add and remove the methods that are being listened to, by add and remove the listen classes.

I am not good with Java but have a fair deal expirence with C#, so i attacked my problem as i would there and created this class.

public class TESPluginDynListener<T> implements Listener {

    TESPlugin plugin;

    public TESPluginDynListener(TESPlugin plugin){
        this.plugin = plugin;
    }

    @EventHandler(ignoreCancelled=false, priority = EventPriority.LOW)
    public void onDynEvent(T event){
        if(event instanceof Event)
            plugin.onEvent((Event)event);
    }
}

This seems to work fine, but my problem is, that the event i have to register do i get as a String, example “some.package.someEvent”, and i have no idea how to translate that into the Type T so i can add the listener class.

So how can i create an instance my class TESPluginDynListener where T is translated from a String? I am not interested in doing a lot of if else, as i want this to be as dynamic as possible!

Here is an idea of what i am trying to do

String eventClass = "some.package.someEvent";

TESPluginDynListener listener = new TESPluginDynListener<Type.FromName(eventClass)>(this);
eventhandeler.RegisterListener(listener);
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T17:06:23+00:00Added an answer on June 14, 2026 at 5:06 pm

    It sounds like you’re looking for Class.forName and Class.newInstance.

    On the other hand, bear in mind that type erasure in generics means you don’t really need to know T in order to build a TESPluginDynListener… you probably want to take Class<T> in the constructor for TESPluginDynListener and use Class.isInstance rather than instanceof within onDynEvent.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

First of all, sorry about the title -- I couldn't figure out one that
I'm sorry about the title I'm just not sure how to describe this one.
Sorry about the title. That was the best I could come up with. Anyways,
sorry about the funky title, I was having trouble coming up with one. First
Sorry about the stupid question however I can't see/ not good enough to solve
sorry about input mistakes, english its not my mother lang. I have this code
Sorry about the strange title, but I am having a small issue if the
Sorry about the strange title. I really have no idea how to express it
Sorry about the terrible title. I have a signed assembly 'Signed.dll' that is a
sorry about the title, I'm not sure how to even describe this, which makes

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.