Skip to content

Instantly share code, notes, and snippets.

@lordcodes
Last active February 11, 2020 07:29
Show Gist options
  • Save lordcodes/f9fed247fc8def39cd7643b6dc6e7298 to your computer and use it in GitHub Desktop.
Save lordcodes/f9fed247fc8def39cd7643b6dc6e7298 to your computer and use it in GitHub Desktop.
Code for my article "Enforcing type safety of IDs in Kotlin"
data class Identifier<EntityT, RawT>(
val rawValue: RawT
)
data class Room(val id: Identifier<Room, UUID>)
data class Meeting(val id: Identifier<Meeting, UUID>)
fun bookMeeting(id: Identifier<Meeting, UUID>) {}
// ❌ Compile error: Type mismatch.
bookMeeting(room.id)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment