简体   繁体   English

sun.reflect.generics.reflectiveObjects.NotImplementedException和org.apache.commons.lang3.NotImplementedException之间有什么区别

[英]What is the difference between sun.reflect.generics.reflectiveObjects.NotImplementedException and org.apache.commons.lang3.NotImplementedException

I have discovered there are 2 NotImplementedException: 我发现有2 NotImplementedException:

  • sun.reflect.generics.reflectiveObjects.NotImplementedException sun.reflect.generics.reflectiveObjects.NotImplementedException
  • org.apache.commons.lang3.NotImplementedException org.apache.commons.lang3.NotImplementedException

Since there is not an available documentation for the first one, I'm not able to understand the difference between them. 由于第一个文档没有可用的文档,因此我无法理解它们之间的区别。 What is this difference? 这有什么区别? Is one of them better than the other one? 其中一个比另一个更好吗?

I have discovered there are 2 NotImplementedException 我发现有2个NotImplementedException

I found more examples than that. 我发现了更多的例子。 It depends on how hard you look ... and where. 这取决于你看上去有多努力……以及在哪里。


Since there is not an available documentation for the first one ... 由于第一个没有可用的文档...

That is because sun.reflect.generics.reflectiveObjects.NotImplementedException is an internal class. 那是因为sun.reflect.generics.reflectiveObjects.NotImplementedException是一个内部类。 The source code says: 源代码说:

"Temporary class used to indicate missing functionality" “用于指示缺少功能的临时类”


What is this difference? 这有什么区别?

They both mean the same thing, more or less. 他们或多或少地意味着同一件事。 Some piece of functionality has not been implemented. 某些功能尚未实现。


Is one of them better than the other one? 其中一个比另一个更好吗?

I assume that you are really asking whether you can and should reuse either of these exceptions in your code. 我假设您确实是在问是否可以并且应该在代码中重用这些异常之一。

  1. Since the sun.reflect... exception is an internal class (see @GhostCat's answer), it is inadvisable to use it in your code. 由于sun.reflect sun.reflect...异常是内部类(请参阅@GhostCat的答案),因此建议在代码中使用它。 There is a chance that the class will "go away" in a future release of Java 1 . 在将来的Java 1版本中,该类有可能“消失”。 That will present problems for your codebase. 这将为您的代码库带来问题。

  2. It is reasonable to reuse the org.apache.commons... exception. 重用org.apache.commons...异常是合理的。 Indeed, my reading of the javadoc, it is designed to be generally reusable. 确实,在阅读Javadoc时,它的设计目的通常可重用。 However: 然而:

    • It is not standard. 这不是标准的。
    • In fact, there are at least two versions of this class, in org.apache.commons.lang and org.apache.commons.lang3 . 实际上,该类至少有两个版本,分别在org.apache.commons.langorg.apache.commons.lang3 (See bullet #1!) (请参阅项目符号1!)
    • You would be (potentially) be adding a new dependency on Apache Commons. 您将(可能)在Apache Commons上添加新的依赖项。 That could increase your maintenance costs; 那会增加您的维护成本; eg if someone were to find security issues in Apache Commons that required patching. 例如,如果有人在需要修补的Apache Commons中发现安全问题。 Also, if your company has anti-opensource management or lawyers ... the effort in getting them to grant an exception to a corporate "no opensource" policy might be too much. 另外,如果您的公司有反开源管理人员或律师,那么……让他们为公司的“无开源”政策授予例外的努力可能会太多。
  3. The other alternatives are to declare your own custom exception, or simply use the existing java.lang.UnsupportedOperationException ... which is standard, doesn't add a new dependency, and won't be removed in a future Java release. 其他替代方法是声明您自己的自定义异常,或仅使用现有的java.lang.UnsupportedOperationException ...,它标准的, 不会添加新的依赖项,并且不会在将来的Java版本中删除。


1. I'm not sure of this, but I think that access to sun.reflect.generics.reflectiveObjects is blocked in Java 9. 1.我不确定,但是我认为Java 9中阻止了对sun.reflect.generics.reflectiveObjects访问。

It is pretty simple: anything that lives in a package starting sun... is (almost always) safe to ignore (there are some rare exceptions, like sun.misc.Unsafe ) 这很简单: 任何生活在从sun开始的程序包中的东西 …… (几乎总是)可以安全地忽略(有一些罕见的例外,例如sun.misc.Unsafe

In other words: these packages that still come with the JDK/JRE are not meant for public usage. 换句话说:这些仍与JDK / JRE一起提供的软件包并不适合公共使用。 Even when they provide something useful - you better look out for "really public" alternatives. 即使它们提供了有用的信息 ,您也最好注意“真正公开”的替代方案。 The main purpose of such classes is to help implementing "internals" of the JVM. 此类的主要目的是帮助实现JVM的“内部”。 They are completely out of your control, and there are almost no "guarantees" whatsoever what happens to them over time. 它们完全不受您的控制,并且随着时间的流逝,几乎没有任何“保证”。

In that sense the answer is: that sun exception is one that you simply should not use; 从这个意义上讲,答案是: sun异常是您根本不应该使用的异常; whereas the apache commons one might be a good candidate. 而apache commons 可能是一个很好的候选人。 The whole point of the commons classes is to be used "publicly". 公地类的全部要点是“公开”使用。

I can answer with this. 我可以回答这个。 What is the difference between com.your.package.NotImplementedException and org.apache.commons.lang3.NotImplementedException ? com.your.package.NotImplementedExceptionorg.apache.commons.lang3.NotImplementedException什么区别?

The sun.reflect.generics.reflectiveObjects.NotImplementedException is JDK internal API, not for usage in user code. sun.reflect.generics.reflectiveObjects.NotImplementedExceptionJDK内部API,不适用于用户代码。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用pptx4j的Java程序抛出org / apache / commons / lang / NotImplementedException - Java program that uses pptx4j throws org/apache/commons/lang/NotImplementedException 测试DAO时出错:sun.reflect.generics.reflectiveObjects.TypeVariableImpl无法强制转换为java.lang.Class - Error testing DAOs: sun.reflect.generics.reflectiveObjects.TypeVariableImpl cannot be cast to java.lang.Class Apache Commons Lang3 与 Apache Commons Text 有什么区别? - What is the difference between Apache Commons Lang3 vs Apache Commons Text? OSGi包无法启动 - 无法解析sun.reflect.generics.reflectiveObjects - OSGi bundles won't start - Unable to resolve sun.reflect.generics.reflectiveObjects org.apache.commons.codec.binary.Base64和com.sun.org.apache.xml.internal.security.utils.Base64之间有什么区别吗? - Is there any difference between org.apache.commons.codec.binary.Base64 & com.sun.org.apache.xml.internal.security.utils.Base64? java.lang.reflect 和 maven org.reflections 有什么区别? - What is the difference between java.lang.reflect and the maven org.reflections? org.apache.commons.dbcp.BasicDataSource和com.ibm.db2.jcc.DB2DataSource有什么区别 - What is difference between org.apache.commons.dbcp.BasicDataSource and com.ibm.db2.jcc.DB2DataSource Apache Commons lang: SerializationUtils.clone() 和 BeanUtils.cloneBean() 有什么区别,什么时候用哪个 - Apache Commons lang: What's difference between SerializationUtils.clone() and BeanUtils.cloneBean(), when to use which 如何解决 org.pdfclown.util.NotImplementedException - how to resolve org.pdfclown.util.NotImplementedException java.lang.NoClassDefFoundError:com.sun.org.apache.commons.beanutils.PropertyUtils - java.lang.NoClassDefFoundError: com.sun.org.apache.commons.beanutils.PropertyUtils
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM