What does quot;optional operationquot; mean in Javadoc of for example Set#add(E)?(“可选操作是什么意思?例如 Set#add(E) 在 Javadoc 中的意思?)
问题描述
在 Set 它在方法规范中说 Optional Operation
例如(我强调)
When in the java documentation for Set it says in the specification of a method Optional Operation
e.g. (emphasis by me)
添加(E e)
如果指定元素不存在,则将其添加到该集合中(可选操作).
这里的可选是什么意思?
What does the optional mean here?
如果我使用 SUN/Oracle 以外的 JVM,该操作可能不会由 Java 的实现提供?
That if I use a JVM other than SUN/Oracle, this operation may not be provided by that implementation of Java?
推荐答案
Set
是一个接口.实现该接口的类不一定需要为可选操作提供实现.
Set
is an interface. Classes implementing that interface do not necessarily need to provide an implementation for an optional operation.
我认为那些可选操作会回到一般的 Collection
接口,其中操作是可选的,这对于 一些 种类的集合没有意义.例如.add
是一个对某种只读集合没有真正用处的操作.它在 Javadoc 中明确说明,因此它成为所有集合类提供的一部分,但使用它的人知道,鉴于 some 集合他们并不确切知道,可能是该方法只是抛出一个 UnsupportedOperationException
.
I think those optional operations go back to the general Collection
interface where operations are made optional which do not make sense for some kinds of collections. E.g. add
is an operation that isn't really useful on some kind of read-only collection. It's spelt out explicitly in the Javadoc so it becomes part of what all collection classes offer but someone using it knows that, given some collection they do not know exactly, it could be that the method just throws an UnsupportedOperationException
.
这篇关于“可选操作"是什么意思?例如 Set#add(E) 在 Javadoc 中的意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:“可选操作"是什么意思?例如 Set#add(E) 在 Javadoc 中的意思?


- 如何使用WebFilter实现授权头检查 2022-01-01
- Jersey REST 客户端:发布多部分数据 2022-01-01
- Spring Boot连接到使用仲裁器运行的MongoDB副本集 2022-01-01
- 从 finally 块返回时 Java 的奇怪行为 2022-01-01
- Safepoint+stats 日志,输出 JDK12 中没有 vmop 操作 2022-01-01
- Eclipse 插件更新错误日志在哪里? 2022-01-01
- value & 是什么意思?0xff 在 Java 中做什么? 2022-01-01
- C++ 和 Java 进程之间的共享内存 2022-01-01
- Java包名称中单词分隔符的约定是什么? 2022-01-01
- 将log4j 1.2配置转换为log4j 2配置 2022-01-01