本来以为写个单例模式的类是最容易的事情了,没想到犯错误了。
public final class SingleHelper{
private static SingleHelper helper = new SingleHelper();
private static SAXParserFactory factory = null;
private SingleHelper() {
factory = SAXParserFactory.newInstance();
factory.setNamespaceAware(true);
factory.setValidating(false);
}
public static synchronized SingleHelpergetInstance() {
if (helper == null) {
return new SingleHelper();
} else {
return helper ;
}
}
public void process() {
...............
}
}
把这段代码贴出来,提醒一下自己。好好学习,天天向上。
类的初始化和对象的初始化。