From 648330da501bd1b2f5f5508508679a189e1127f1 Mon Sep 17 00:00:00 2001 From: Roman Golyshev Date: Mon, 16 Oct 2023 17:42:08 +0200 Subject: [PATCH] [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() // 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 --- core/util.runtime/src/org/jetbrains/kotlin/utils/SmartSet.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/util.runtime/src/org/jetbrains/kotlin/utils/SmartSet.kt b/core/util.runtime/src/org/jetbrains/kotlin/utils/SmartSet.kt index 64a71eca352..71f8657dd82 100644 --- a/core/util.runtime/src/org/jetbrains/kotlin/utils/SmartSet.kt +++ b/core/util.runtime/src/org/jetbrains/kotlin/utils/SmartSet.kt @@ -25,7 +25,7 @@ import java.util.* * Also, [iterator] returns an iterator which does not support [MutableIterator.remove]. */ @Suppress("UNCHECKED_CAST") -class SmartSet private constructor() : AbstractSet() { +class SmartSet private constructor() : AbstractMutableSet() { companion object { private const val ARRAY_THRESHOLD = 5