【发布时间】:2013-08-18 15:26:53
【问题描述】:
我正在开发一个使用 this 示例作为基础的应用程序。向下滚动到名为“DetailsFragment”的类。你会看到这个方法:
public static DetailsFragment newInstance(int index) {
DetailsFragment f = new DetailsFragment();
// Supply index input as an argument.
Bundle args = new Bundle();
args.putInt("index", index);
f.setArguments(args);
return f;
}
为什么这个方法是静态的?这不能像这样的常规构造函数那样完成吗:
public DetailsFragment(int index) {
Bundle args = new Bundle();
args.putInt("index", index);
this.setArguments(args);
}
然后当你需要对象的时候就去:
DetailsFragment f = new DetailsFragment(somevalue);
我不明白为什么这个方法是静态的。
【问题讨论】:
标签: java android class methods static