Java - 构造函数是静态的吗? [英] Java - are constructors static?
本文介绍了Java - 构造函数是静态的吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我刚刚写了一个这样的构造函数:
I just wrote a constructor like this:
public ArchivesManager(String identifier) {
String[] components = String.split("\nNEW");
}
但是有一个错误信息:non-static method split(java.lang.String) cannot be reference from a static context
.我知道那个错误信息,但为什么构造函数是静态的?!
But there's an error message: non-static method split(java.lang.String) cannot be referenced from a static context
. I know that error message, but why is the constructor static?!
推荐答案
这是因为应该在 String 对象上调用 split.即
It's because split should be called on a String object. I.e.
String foo = "Hello, world";
String[] arr = foo.split(",");
这篇关于Java - 构造函数是静态的吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文