我有以下代码URLStreamHandlers
通过访问静态包范围的方法来检索Java和Java 8中可用的http和https的默认值URL.getURLStreamHandler()
:
private URLStreamHandler getURLStreamHandler(String protocol) {
try {
Method method = URL.class.getDeclaredMethod("getURLStreamHandler", String.class);
method.setAccessible(true);
return (URLStreamHandler) method.invoke(null, protocol);
} catch (Exception e) {
logger.warning("could not access URL.getUrlStreamHandler");
return null;
}
}
在带有竖锯的Java 9中这是否仍然可能还是会禁止以这种方式修改可见性?
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句