Problem Statement
How do inline functions and reified type parameters work together and what are their use cases?
Explanation
Inline functions have their code copied to the call site instead of creating function calls, eliminating overhead for small functions especially higher-order functions with lambdas. When you make generic functions inline, you can use reified modifier to preserve type information at runtime, enabling runtime type checks and class references.
Reified works because inlining substitutes actual type at each call location, so inline fun less than reified T greater than filterIsInstance can check if elements are of type T using is operator. Without reified, generic types are erased at runtime requiring explicit class parameters.
Common use cases include extension functions like startActivity less than reified T colon Activity greater than in Android where T provides the Activity class to start, filterIsInstance for type-safe collection filtering, and JSON parsing where type information determines deserialization. Reified enables cleaner APIs without explicit class parameters.
Inline with reified has costs: increased code size from copying function body to each call site, and inability to store reified functions in variables or pass them as non-inline parameters. Use judiciously for small frequently-called functions where benefits outweigh costs.
