Has anyone tried using custom types for ids in java?
I considered doing it on a recent project, but it doesn't seem very common so I was reluctant to introduce it.
I considered doing it on a recent project, but it doesn't seem very common so I was reluctant to introduce it.
It was really nice in my Kotlin project because we were dealing with legacy data structures with very confusing names—being able to guarantee that a UserID doesn't accidentally get passed where a UserDataID was expected helped prevent a lot of the bugs that plagued the legacy apps.
Added benefit, as always when leaning into the type system more, is a reduction in the number of unit tests required. The need to test that `update_user(group_id)` fails (because a non-user ID was passed) simply disappears.
Not sure whether I’d do it again or not. It’s hard to say how much benefit that I’m getting out of them.