[英]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:
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. 我假设您确实是在问是否可以并且应该在代码中重用这些异常之一。
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.
这将为您的代码库带来问题。
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:
然而:
org.apache.commons.lang
and org.apache.commons.lang3
. org.apache.commons.lang
和org.apache.commons.lang3
。 (See bullet #1!) 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.NotImplementedException
和org.apache.commons.lang3.NotImplementedException
什么区别?
The sun.reflect.generics.reflectiveObjects.NotImplementedException
is JDK
internal API, not for usage in user code. sun.reflect.generics.reflectiveObjects.NotImplementedException
是JDK
内部API,不适用于用户代码。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.