我目前在 Java 中使用一个单独的线程,它可能用于许多不同的功能,我想知道是否有一种方法可以将实际函数调用的命令作为参数传递。这看起来类似于:
class myWorkerThread implements Runnable
{
private (<String/whatever other type>) runCommand;
public myWorkerThread(<String/whatever other type> <my command>)
{
}
public void run()
{
//Actually run that command.
}
}
我希望得到一个工具,不会让我使用难看的 switch case 语句或类似的东西。我要求线程运行的不同函数具有不同的参数,但我希望能够使用同一个线程运行它们。
后续问题/其他资源的链接非常棒。
谢谢。
最佳答案
关于java - 将实际命令作为参数传递 Java,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3613789/