Implement equals, hashCode and toString for Objective-C objects
This commit is contained in:
committed by
SvyatoslavScherbina
parent
6b042a5510
commit
4e285a5ef4
@@ -23,6 +23,21 @@ fun run() {
|
||||
replacePairElements(pair, 1, 2)
|
||||
pair.swap()
|
||||
println("${pair.first}, ${pair.second}")
|
||||
|
||||
// equals and hashCode (virtually):
|
||||
val map = mapOf(foo to pair, pair to foo)
|
||||
|
||||
// equals (directly):
|
||||
if (!foo.equals(pair)) {
|
||||
// toString (directly):
|
||||
println(map[pair].toString() + map[foo].toString() == foo.description() + pair.description())
|
||||
}
|
||||
|
||||
// hashCode (directly):
|
||||
if (foo.hashCode() == foo.hash().toInt()) {
|
||||
// toString (virtually):
|
||||
println(map.keys.map { it.toString() }.min() == foo.description())
|
||||
}
|
||||
}
|
||||
|
||||
fun MutablePairProtocol.swap() {
|
||||
|
||||
Reference in New Issue
Block a user