[kotlin] Make SmartSet implement MutableSet for more type-safety
`AbstractSet` is a java class, and it brings flexible types with it.
Because of it, it was possible to write the following code:
```kt
fun usage() {
val mySet = SmartSet.create<String>() // should not contain nulls
mySet += null // compiles because of flexible types
}
```
Using `AbstractMutableSet`
as a base class does not change the implementation,
but explicitly adds a proper kotlin `MutableSet`
interface to the class, making it more type-safe
This commit is contained in:
committed by
Space Team
parent
15cdc971bf
commit
648330da50
@@ -25,7 +25,7 @@ import java.util.*
|
|||||||
* Also, [iterator] returns an iterator which does not support [MutableIterator.remove].
|
* Also, [iterator] returns an iterator which does not support [MutableIterator.remove].
|
||||||
*/
|
*/
|
||||||
@Suppress("UNCHECKED_CAST")
|
@Suppress("UNCHECKED_CAST")
|
||||||
class SmartSet<T> private constructor() : AbstractSet<T>() {
|
class SmartSet<T> private constructor() : AbstractMutableSet<T>() {
|
||||||
companion object {
|
companion object {
|
||||||
private const val ARRAY_THRESHOLD = 5
|
private const val ARRAY_THRESHOLD = 5
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user