LastExceed
01/21/2020, 11:17 AMLong
) and i figured it might be worth using a typealias or inline class to clarify that using this number for e.g. multiplication makes no sense.
if possible, I am looking for a generalized answer so I know how to make this decision myself in the futureAndrás Bubics
01/21/2020, 11:22 AMtypealias
, especially if you expect the compiler to help you avoid simple errors (like accidentally comparing incomparable types).
I like to restrict typealias
to things like lambda signatures, where they reduce verbosity, but don't give false confidence. It can also help as a stepping stone for refactoring.LastExceed
01/21/2020, 11:24 AMAndrás Bubics
01/21/2020, 11:25 AMLastExceed
01/21/2020, 11:25 AMAndrás Bubics
01/21/2020, 11:25 AMLastExceed
01/21/2020, 11:26 AMAndrás Bubics
01/21/2020, 11:26 AMLastExceed
01/21/2020, 11:27 AMAndrás Bubics
01/21/2020, 11:27 AMAndrás Bubics
01/21/2020, 11:28 AMLastExceed
01/21/2020, 11:29 AMAndrás Bubics
01/21/2020, 11:30 AMAndrás Bubics
01/21/2020, 11:30 AMRay Eldath
01/21/2020, 11:57 AMtypealias
to lambda signature". I use typeclias
mostly for alias lambda signature and generic type, like shorten Predicate<*, *>
to AnyPredicate
😉 but it's just my experience, so it depends.Mike
01/21/2020, 1:37 PMinline class
is definitely intended for the MessageId case. Providing stronger typing while minimizing/eliminating the overhead incurred creating, and deleting a bunch of classes. As the name implies, the compiler will attempt to inline the class to the type in bytecode. Similar to what the Java compiler already does for Integer etc types.
But as noted, it's still in experimental stages. For Kotlin, that generally means that the usage or implementation is subject to change, and not that it's an unstable feature. Still, you have to explicitly let the compiler know you're ok with taking on this risk/tech debt.