我面对下面的代码
XmlReader xmlreader =
XmlReader.Create("http://www.ecb.int/stats/eurofxref/eurofxref-daily.xml");
在这里创建一个新对象XmlReader
,它只是使用的调用方法XmlReader
。
我知道这里Create
是静态方法,但对我来说有点奇怪。我曾经利用new
单词命令命令创建新实例。
谁能告诉我这条线是如何工作的?
您正在调用的方法可以为您实现:
public class XmlReader {
public static XmlReader Create(String url) {
// There's probably a lot of fancy code in this method, but it'll use new somewhere
return new XmlReader(...);
}
}
(可以new
通过使用称为反射的技术来完全避免,但这不是这里要发生的事情。)
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句