[英]Why java.util.BitSet does not implement java.util.Set
Why java.util.BitSet
does not implement java.util.Set<Integer>
interface. 为什么java.util.BitSet
不实现java.util.Set<Integer>
接口。 Especially when it can easily do so. 尤其是当它可以轻松做到这一点时。 Also BitSet is used to maintain if an integer was "switched on or not", Set also does exactly the same. 此外,还使用BitSet来维护是否“打开或不打开”一个整数,Set的功能也完全相同。 So BitSet
is a Set<Integer>
. 所以BitSet
是一个Set<Integer>
。 Referring to some comments saying that 提到一些评论说
Now take a look at the methods of BitSet. 现在看一下BitSet的方法。 The purpose of the class is to perform logical operations on a collection of bits that are in a certain order. 该类的目的是对按一定顺序的位集合执行逻辑运算。
I would still say that BitSet
is a Set<Integer>
which also provides additional set of operations. 我仍然会说BitSet
是Set<Integer>
,它还提供其他操作集。
Since the comments don't make it obvious enough: 由于注释不够明显:
You say "BitSet is effectively an efficient set. BitSet is a Set" - no it is not. 您说“ BitSet实际上是一个有效的集合。BitSet是一个集合”-不,不是。 A Set
is a collection which contains no duplicate elements. Set
是不包含重复元素的集合。
Now imagine a Set<Bit>
. 现在想象一个Set<Bit>
。 Since a bit can only be 1 or 0, that will be a pretty boring set of a maximum size of 2. 由于一个位只能是1或0,这将是一个相当无聊的设置,最大大小为2。
Now take a look at the methods of BitSet
. 现在看一下BitSet
的方法 。 The purpose of the class is to perform logical operations on a collection of bits that are in a certain order. 该类的目的是对按一定顺序的位集合执行逻辑运算。 That has nothing to do with a Set
. 与Set
无关。
java.util.BitSet
is in the JDK since version 1.0, java.util.Set
entered the stage with JDK 1.2. java.util.BitSet
是在JDK因为版本1.0, java.util.Set
输入的阶段与JDK 1.2。 So BitSet
cannot implement Set
. 因此, BitSet
无法实现Set
。
If you need a Set<>
implementation backed by a BitSet
, that does not seem to hard to implement using a backing BitSet
. 如果您需要一个由BitSet
支持的Set<>
实现,那么使用支持BitSet
似乎并不难实现。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.