On second thought, it might not be such a bad idea...
# android-architecture
t
On second thought, it might not be such a bad idea as long as you use a different type to make it clear that it's unsafe. Here's how I would do it: If you only need this once, call it
UserIdAndName
. If you need a lot of those (possibly with many fields), then call it
UserSlice
or whatever and make it a copy of
User
where every field of type
T
becomes a
Optional<T>
. You can also generate those with an annotation processor fairly easily (disregarding the problems with mapped types in Kotlin). I'm sure there's a more elegant solution (particularly if you have access to structural types) but if there's one thing I have learned in my young career, it's not to get hung up on such small issues or you will never finish anything.