ryy*_*yst 3 java static constructor
我刚写了一个像这样的构造函数:
public ArchivesManager(String identifier) {
String[] components = String.split("\nNEW");
}
Run Code Online (Sandbox Code Playgroud)
但是有一条错误信息:non-static method split(java.lang.String) cannot be referenced from a static context.我知道错误信息,但为什么构造函数是静态的?!
这是因为应该在String对象上调用split.即
String foo = "Hello, world";
String[] arr = foo.split(",");
Run Code Online (Sandbox Code Playgroud)