Zoltan Demant
07/03/2025, 11:27 AMsealed interface BranchIdentifier {
val key: String
}
@JvmInline
value class A(override val key: String) : BranchIdentifier
@JvmInline
value class B(override val key: String) : BranchIdentifier
fun main() {
val collection = mutableSetOf<BranchIdentifier>()
collection.add(A("5"))
collection.add(B("5"))
println(collection.size) // Prints 2
println(collection.contains(A("5"))) // true
println(collection.contains(B("5"))) // true
println(collection.remove(A("5"))) // true
println(collection.contains(B("5"))) // true
println(collection.size) // 1
}
Joffrey
07/03/2025, 11:29 AMZoltan Demant
07/03/2025, 11:30 AMZoltan Demant
07/03/2025, 11:30 AMJoffrey
07/03/2025, 11:35 AMJoffrey
07/03/2025, 11:36 AMJoffrey
07/03/2025, 11:39 AMList<A>
it will contain boxed values at runtime. If you're using a val branchId: BranchIdentifier = A("5")
it should also use a boxed value IIRCephemient
07/03/2025, 11:41 AMvalue
part of value classes disappears as soon as you box them - same as primitivesZoltan Demant
07/03/2025, 11:46 AMEugen Martynov
07/04/2025, 1:33 PMDan Rusu
07/04/2025, 3:28 PMZoltan Demant
07/04/2025, 4:03 PMDan Rusu
07/04/2025, 4:11 PMZoltan Demant
07/04/2025, 4:14 PMZoltan Demant
07/04/2025, 4:14 PMZoltan Demant
07/04/2025, 4:15 PMDan Rusu
07/04/2025, 4:16 PM