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 中的意思?
基础教程推荐
- Struts2 URL 无法访问 2022-01-01
- 问题http://apache.org/xml/features/xinclude测试日志4j 2 2022-01-01
- 修改 void 函数的输入参数,然后读取 2022-01-01
- REST Web 服务返回 415 - 不支持的媒体类型 2022-01-01
- RabbitMQ:消息保持“未确认"; 2022-01-01
- 使用堆栈算法进行括号/括号匹配 2022-01-01
- 无法复制:“比较方法违反了它的一般约定!" 2022-01-01
- 存储 20 位数字的数据类型 2022-01-01
- 如何对 Java Hashmap 中的值求和 2022-01-01
- Spring AOP错误无法懒惰地为此建议构建thisJoinPoin 2022-09-13
