Hi there. I have a lot of ids across my android ap...
# announcements
u
Hi there. I have a lot of ids across my android app, which are just strings. Would it be a good practice to use typealias in the following manner:
Copy code
typealias Id = String
Thanks!
r
in case the id is for a type then I would suggest you use an inline class with a type parameter, something like:
Copy code
inline class Id<T>(val value: String)
👍 1
t
unfortunately, depending of the context, inline classes could not be usable. for instance: https://github.com/spring-projects/spring-framework/issues/21998 we currently do as you are asking @ubu but personally I don’t find it too useful, as
fun get(id: Id)
would accept any String and any other String typealiased anyway. If you can, I would also suggest inline classes
u
thanks!