T
T
timonestudio2021-12-29 12:29:49
Java
timonestudio, 2021-12-29 12:29:49

Class into method argument how to do?

public static void SetExecutor(String cmd, Class cls) {
    this.getCommand(cmd).setExecutor(new "class_name"());
  }

How to do it?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Gornostaev, 2021-12-29
@timonestudio

Without reflection, in any way, and it is better not to use reflection. The code looks type-unsafe. It's better to pass an interface instance or a reference to an interface constructor.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question