合并 类 时 Java 没有关闭实例错误
No closing instance error with Java when combining classes
我正在尝试将我单独的 Java 个文件放入 1 class。看起来像这样。
public class oneClass {
class Request {
public double a;
public double b;
public double c;
public Request(double a, double b, double c) {
this.a = a;
this.b = b;
this.c = c;
}
}
public static class Controller {
public static void main(String[] args) {
Request req = new Request(time, 0, 0);
// some code
}
}
}
但是我运行出错了
"Exception in thread "main" java.lang.Error: Unresolved compilation
problem: No enclosing instance of type oneClass is accessible. Must
qualify the allocation with an enclosing instance of type problem2
(e.g. x.new A() where x is an instance of problem2).
怎么回事?
如果要在外部 class.
的实例之外构造它,则需要将 Request
设为静态 class
我正在尝试将我单独的 Java 个文件放入 1 class。看起来像这样。
public class oneClass {
class Request {
public double a;
public double b;
public double c;
public Request(double a, double b, double c) {
this.a = a;
this.b = b;
this.c = c;
}
}
public static class Controller {
public static void main(String[] args) {
Request req = new Request(time, 0, 0);
// some code
}
}
}
但是我运行出错了
"Exception in thread "main" java.lang.Error: Unresolved compilation problem: No enclosing instance of type oneClass is accessible. Must qualify the allocation with an enclosing instance of type problem2 (e.g. x.new A() where x is an instance of problem2).
怎么回事?
如果要在外部 class.
的实例之外构造它,则需要将Request
设为静态 class