Last active
          February 11, 2020 07:29 
        
      - 
      
 - 
        
Save lordcodes/f9fed247fc8def39cd7643b6dc6e7298 to your computer and use it in GitHub Desktop.  
    Code for my article "Enforcing type safety of IDs in Kotlin"
  
        
  
    
      This file contains hidden or 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
    
  
  
    
  | 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