If I use MutableSet with sealed class, the MutableSet accept all duplicated content.
Sample:
sealed class LoginSavedCommand {
class Login(val email: String, val password: String) : LoginSavedCommand()
class SaveData(val email: String, val password: String) : LoginSavedCommand()
}
fun main(args: Array<String>) {
val mSet: MutableSet<LoginSavedCommand> = hashSetOf()
mSet.add(LoginSavedCommand.Login("oba", "pass"))
mSet.add(LoginSavedCommand.Login("faiii", "blabla"))
if (mSet.add(LoginSavedCommand.Login("oba", "pass"))) {
println("don't")
} else {
println("do")
}
}
I passed the same values to LoginSavedCommand.Login
, but the MutableSet
keep accepting add the same value (on the sample println
print “don’t”, and I need to print “do”, because I can prevent duplicated content using this selaed class
)