Last active
May 2, 2021 15:43
-
-
Save sorokod/c30ccc4b85342144ce887378b37187b7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* A type safe wrapper for comparable IDs | |
**/ | |
import java.util.UUID | |
abstract class RefId<T : Comparable<T>> : Comparable<RefId<T>> { | |
abstract val value: T | |
override fun compareTo(other: RefId<T>) = value.compareTo(other.value) | |
} | |
data class UsrId(override val value: UUID) : RefId<UUID>() | |
data class Usr(val id: UsrId) | |
fun main() { | |
val uuid1 = UUID.randomUUID() | |
val uuid2 = UUID.randomUUID() | |
println(UsrId(uuid1) == UsrId(uuid1)) | |
println(UsrId(uuid1) == UsrId(uuid2)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment