【发布时间】:2020-06-03 11:02:25
【问题描述】:
我有我自己的System 类,在同一个包中有一个测试类,测试方法在 System 类中声明。我还创建了一个带有 3 个参数的 System 构造函数。当我创建一个构造函数来测试我的 IDE 中的方法时,程序运行正常(我曾在需要使用 System.method 的地方使用 java.util.System)但 IDE 知道我在创建时指的是我自己的类构造函数。但是,当我尝试从命令行运行我的测试类时,它甚至不会编译:
error: constructor System in class System cannot be applied to given types;
System sys = new System("String1", "String2", 20);
^
required: no arguments
found: String,String,int
reason: actual and formal argument lists differ in length
我的猜测是,正在调用 java.util.System 构造函数(没有参数)而不是我的构造函数,这会导致整个程序崩溃。有谁知道如何修复它,为什么它只发生在命令行而不是 IDE 中?
【问题讨论】: