gpt4 book ai didi

java - 如何使 Java 中的 XPathFactory newInstance 失败?

转载 作者:行者123 更新时间:2023-11-30 07:43:09 26 4
gpt4 key购买 nike

XPathFactory.newInstance(String uri) 的文档是 here

我试图让这个失败,如下所示:

println(System.getProperty("DEFAULT_PROPERTY_NAME"));
System.setProperty("DEFAULT_PROPERTY_NAME", "dummy");
println(System.getProperty("DEFAULT_PROPERTY_NAME"));
XPathFactory xPathFactory = XPathFactory.newInstance();
println(xPathFactory.getClass());

我得到的输出是:

null
dummy
class org.apache.xpath.jaxp.XPathFactoryImpl

我预计类加载器会因要点而失败:

If the system property DEFAULT_PROPERTY_NAME + ":uri" is present, where uri is the parameter to this method, then its value is read as a class name. The method will try to create a new instance of this class by using the class loader, and returns it if it is successfully created.

但事实并非如此,我显然错过了一些东西。

我做错了什么?

最佳答案

I am expecting that the ClassLoader will fail due to the bullet point:

这个要点指的是方法:

public static final XPathFactory newInstance(String uri)

但是你正在打电话:

public static final XPathFactory newInstance()

其中指出:

This method is functionally equivalent to:

newInstance(DEFAULT_OBJECT_MODEL_URI)

Since the implementation for the W3C DOM is always available, this method will never fail.

关于java - 如何使 Java 中的 XPathFactory newInstance 失败?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34372019/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com