public class MainClass {
public void main(String[] args) {
Grid.simulator(args); //static method that I can actually call
Engine.main;//what I want to call
}
}
问题是:Engine.main
不能是静态的。这就是为什么:临时类。方法调用,用于非静态类/方法
class Engine {
String command;
public void main() {
this.CommandLine(command); //Calls the Method which has the user input
this.ProcessCommand(command); //Calls the Method that will process the input
}
}
我明白,我不能调用非静态方法,但我想一个变通的: 想如果我分配一个东西到CommandLine
和ProcessCommand
它的工作,就好像它是一个静态上下文中的非初始化变量。像这样:
class SomeClass {
public static void main(String[] args) {
int number = null;
number = System.Nextint;
System.out.print(number);
}
}
//In this code, either don't put it as static OR initialize 'number', even if as null.
将东西类似工作this.Something
?如果是,那怎么样?
请请格式化您的代码。这确实难以辨认。 –
请尝试提供更完整的代码示例,并尝试澄清一点说明。现在确实很难遵循。 – Dukeling
不要问含糊的假设性问题。写下你想问什么,看看结果是什么。 –