#How would I get the instance of a listener?

6 messages · Page 1 of 1 (latest)

shadow violet
#

I am iterating through a list of classes that implement a listener.

Example:
public class Demo implements Listener

On this line here I try to get the instance, but I do not know how.

Listener listener = (Listener) Class.forName(classPath).?????????;

How can I get the instance of this interface?

hollow estuaryBOT
#

This post has been reserved for your question.

Hey @shadow violet! Please use /close or the Close Post button above when you're finished. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.

TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.

ornate lotus
#

.getDeclaredConstructor(PARAMETERS).newInstance(ARGUMENTS);

#

PARAMETERS is just the Classes of all constructor parameters (or leave it out if there are none)

#

ARGUMENTS refers to the arguments/the actual objects passed to the constructor