<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Majid</title>
    <description>The latest articles on DEV Community by Majid (@majid460).</description>
    <link>https://dev.to/majid460</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3780851%2F43961c13-a89f-4903-a037-b3613e13247e.jpeg</url>
      <title>DEV Community: Majid</title>
      <link>https://dev.to/majid460</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/majid460"/>
    <language>en</language>
    <item>
      <title>Beating Type Erasure: How Kotlin’s inline + reified Unlock Compile-Time Superpowers</title>
      <dc:creator>Majid</dc:creator>
      <pubDate>Thu, 19 Feb 2026 11:17:05 +0000</pubDate>
      <link>https://dev.to/majid460/beating-type-erasure-how-kotlins-inline-reified-unlock-compile-time-superpowers-3c0f</link>
      <guid>https://dev.to/majid460/beating-type-erasure-how-kotlins-inline-reified-unlock-compile-time-superpowers-3c0f</guid>
      <description>&lt;h4&gt;
  
  
  Unlocking Kotlin's inline and reified
&lt;/h4&gt;

&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;Kotlin is packed with powerful features that help developers write expressive and efficient code, but few are as misunderstood (or underused) as the &lt;code&gt;inline&lt;/code&gt; keyword and its companion, &lt;code&gt;reified&lt;/code&gt;. At first glance, they might seem like advanced compiler tricks reserved for library authors. In reality, they solve everyday problems: eliminating lambda overhead, enabling type-safe generic functions, and making your code both cleaner and more performant. In this article, we'll break down exactly what &lt;code&gt;inline&lt;/code&gt; and &lt;code&gt;reified&lt;/code&gt; do, why they exist, and when you should reach for them.&lt;/p&gt;




&lt;h2&gt;
  
  
  What Is the inline Keyword?
&lt;/h2&gt;

&lt;p&gt;The &lt;code&gt;inline&lt;/code&gt; keyword is used to optimize higher-order functions by reducing the runtime overhead associated with function calls, particularly when lambda expressions are involved. When a function is marked as &lt;code&gt;inline&lt;/code&gt;, the Kotlin compiler substitutes the function body directly into the places where the function is called. This substitution eliminates the need to allocate memory for function objects and avoids the overhead of lambda invocation.&lt;/p&gt;




&lt;h2&gt;
  
  
  How Inlining Works Under the Hood
&lt;/h2&gt;

&lt;p&gt;Normally, passing a lambda as a parameter involves creating an object to represent the lambda and invoking its method. This can introduce performance overhead, especially in performance-critical scenarios. Marking a function as &lt;code&gt;inline&lt;/code&gt; eliminates this overhead by inserting the actual function body and lambda code directly into the call site. Consider the following example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight kotlin"&gt;&lt;code&gt;&lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="k"&gt;inline&lt;/span&gt; &lt;span class="k"&gt;fun&lt;/span&gt; &lt;span class="nf"&gt;inlineFun&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;lambda&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="nc"&gt;Unit&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"COMPUTING started"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="nf"&gt;lambda&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="c1"&gt;// The code from the lambda will be copied here&lt;/span&gt;
    &lt;span class="nf"&gt;println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Computing ended"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;fun&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;inlineFun&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nf"&gt;println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Performing heavy computing"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example, the &lt;code&gt;inlineFun&lt;/code&gt; function is marked as &lt;code&gt;inline&lt;/code&gt;. The compiler will replace the call to &lt;code&gt;inlineFun&lt;/code&gt; with its body, including the lambda code, resulting in fewer object allocations and better runtime performance.&lt;/p&gt;




&lt;h2&gt;
  
  
  Performance Benefits: Lambda Overhead Explained
&lt;/h2&gt;

&lt;p&gt;Without using &lt;code&gt;inline&lt;/code&gt;, every time you pass a lambda to a higher-order function, the compiler must create a function object on the heap to represent that lambda. This includes:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Object Allocation:&lt;/strong&gt; A new object is created on the heap to hold the lambda's code.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Memory Overhead:&lt;/strong&gt; This object consumes memory.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Virtual Method Call:&lt;/strong&gt; Invoking the lambda requires a virtual method call (&lt;code&gt;invoke()&lt;/code&gt;), which is slightly slower than a direct method call.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;In a function that is called frequently, especially within a loop, this overhead of creating many small &lt;code&gt;Function&lt;/code&gt; objects can add up and put pressure on the garbage collector. The &lt;code&gt;inline&lt;/code&gt; keyword solves this completely — when a function is inlined, the compiler doesn't create a &lt;code&gt;Function&lt;/code&gt; object for the lambda. Instead, it pastes the body of the lambda directly where it is called.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight kotlin"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Inline Function&lt;/span&gt;
&lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="k"&gt;inline&lt;/span&gt; &lt;span class="k"&gt;fun&lt;/span&gt; &lt;span class="nf"&gt;inlineFun&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;lambda&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="nc"&gt;Unit&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"COMPUTING started"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="nf"&gt;lambda&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="c1"&gt;// The code from the lambda will be copied here&lt;/span&gt;
    &lt;span class="nf"&gt;println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Computing ended"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;// Non Inline Function&lt;/span&gt;
&lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="k"&gt;fun&lt;/span&gt; &lt;span class="nf"&gt;nonInlined&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;lambda&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="nc"&gt;Unit&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"COMPUTING started"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="nf"&gt;lambda&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="c1"&gt;// This is a virtual call to a Function object&lt;/span&gt;
    &lt;span class="nf"&gt;println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Computing ended"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;fun&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;inlineFun&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nf"&gt;println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Performing heavy computing"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="nf"&gt;nonInlined&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nf"&gt;println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Performing heavy computing"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;// What the compiler generates&lt;/span&gt;

&lt;span class="k"&gt;fun&lt;/span&gt; &lt;span class="nf"&gt;main_compiled&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// For nonInlined, a Function object is created&lt;/span&gt;
    &lt;span class="nf"&gt;println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"COMPUTING started"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="nc"&gt;Function0&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nf"&gt;println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Performing heavy computing"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;}.&lt;/span&gt;&lt;span class="nf"&gt;invoke&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="nf"&gt;println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Computing ended"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="c1"&gt;// For inline Function, the code is copied directly&lt;/span&gt;
    &lt;span class="nf"&gt;println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"COMPUTING started"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="nf"&gt;println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Performing heavy computing"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// No object, no virtual call&lt;/span&gt;
    &lt;span class="nf"&gt;println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Computing ended"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  Introducing reified: Retaining Type Information at Runtime
&lt;/h2&gt;

&lt;p&gt;Another powerful feature unlocked by &lt;code&gt;inline&lt;/code&gt; is the ability to use &lt;code&gt;reified&lt;/code&gt; type parameters. In Kotlin, generics are erased at runtime due to type erasure in the JVM, which means you cannot access the type of a generic parameter &lt;code&gt;T&lt;/code&gt; at runtime (e.g., you can't do &lt;code&gt;T::class&lt;/code&gt;). However, by marking a function as &lt;code&gt;inline&lt;/code&gt;, you can use the &lt;code&gt;reified&lt;/code&gt; keyword to retain type information at runtime. This is particularly useful for type-checking or casting.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight kotlin"&gt;&lt;code&gt;&lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="k"&gt;inline&lt;/span&gt; &lt;span class="k"&gt;fun&lt;/span&gt; &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="k"&gt;reified&lt;/span&gt; &lt;span class="nc"&gt;T&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;isInstance&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;value&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;Any&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt; &lt;span class="nc"&gt;Boolean&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;value&lt;/span&gt; &lt;span class="k"&gt;is&lt;/span&gt; &lt;span class="nc"&gt;T&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;fun&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;isInstance&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;String&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;(&lt;/span&gt;&lt;span class="s"&gt;"This is string"&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt; &lt;span class="c1"&gt;// true&lt;/span&gt;
    &lt;span class="nf"&gt;println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;isInstance&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Int&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;(&lt;/span&gt;&lt;span class="s"&gt;"This is Int"&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;       &lt;span class="c1"&gt;// false&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example, &lt;code&gt;reified&lt;/code&gt; allows the type parameter &lt;code&gt;T&lt;/code&gt; to be used in a type-checking operation (&lt;code&gt;is T&lt;/code&gt;) at runtime. This is extremely useful for creating clean, type-safe APIs, especially in libraries. A common use case in Android is finding a Fragment by its type: &lt;code&gt;findFragment&amp;lt;MyFragment&amp;gt;()&lt;/code&gt;.&lt;/p&gt;




&lt;h2&gt;
  
  
  inline + reified in Action: Real-World Examples
&lt;/h2&gt;

&lt;p&gt;When a function is marked as &lt;code&gt;inline&lt;/code&gt;, the Kotlin compiler substitutes the function's code directly at the call site. If a type parameter is declared as &lt;code&gt;reified&lt;/code&gt;, it ensures that the type information is available during this inlining process, allowing the type to be accessed and manipulated at runtime. One of the most common use cases of &lt;code&gt;reified&lt;/code&gt; is simplifying generic types in scenarios where type information is required at runtime, such as reflection, type casting, or creating instances of classes.&lt;/p&gt;




&lt;h2&gt;
  
  
  Benefits of Using reified
&lt;/h2&gt;

&lt;p&gt;When working with generics in Kotlin, using the &lt;code&gt;reified&lt;/code&gt; keyword in &lt;code&gt;inline&lt;/code&gt; functions unlocks powerful capabilities that are otherwise restricted due to type erasure. Here are the key advantages:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Type Safety:&lt;/strong&gt; Allows for safer code by reducing the need for unchecked casts.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Cleaner Syntax:&lt;/strong&gt; Removes the requirement for explicitly passing &lt;code&gt;Class&lt;/code&gt; objects as parameters.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Runtime Reflection:&lt;/strong&gt; Enables easier runtime operations like checking types or accessing class metadata.
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight kotlin"&gt;&lt;code&gt;&lt;span class="k"&gt;inline&lt;/span&gt; &lt;span class="k"&gt;fun&lt;/span&gt; &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="k"&gt;reified&lt;/span&gt; &lt;span class="nc"&gt;T&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;List&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Any&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;.&lt;/span&gt;&lt;span class="nf"&gt;filterByType&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt; &lt;span class="nc"&gt;List&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;T&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;filterIsInstance&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;T&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;()&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;fun&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;val&lt;/span&gt; &lt;span class="py"&gt;mixedList&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;listOf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"Class A"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mf"&gt;2.5&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"Programming"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="kd"&gt;val&lt;/span&gt; &lt;span class="py"&gt;stringList&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;mixedList&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;filterByType&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;String&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;()&lt;/span&gt;
    &lt;span class="nf"&gt;println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;stringList&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// Outputs: [Class A, Programming]&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here, the &lt;code&gt;filterByType&lt;/code&gt; function retains type information through &lt;code&gt;reified&lt;/code&gt;, enabling type-specific filtering.&lt;/p&gt;




&lt;h2&gt;
  
  
  Limitations of reified and Inline
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Inline
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Code bloat&lt;/strong&gt; — large functions copied at every call site increase binary size and can cause CPU cache misses.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Large functions&lt;/strong&gt; — substantial logic should stay non-inlined to keep your APK lighter and runtime efficient.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;No overriding&lt;/strong&gt; — &lt;code&gt;inline&lt;/code&gt; functions are implicitly final, making them unsuitable for polymorphic or inheritance-based designs.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;No lambdas, no benefit&lt;/strong&gt; — without lambda parameters, the JVM's JIT compiler handles inlining better than doing it manually.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Avoid with recursion&lt;/strong&gt; — recursive functions cannot be inlined; the compiler will warn you if you try.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Limited use as private functions&lt;/strong&gt; — private &lt;code&gt;inline&lt;/code&gt; functions offer little advantage if they aren't reused across multiple call sites.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Reified
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;Only works inside &lt;code&gt;inline&lt;/code&gt; functions — it cannot be used for general-purpose generics outside that context.&lt;/li&gt;
&lt;li&gt;The JVM's type erasure is why this limitation exists; generic types are lost at runtime by default.&lt;/li&gt;
&lt;li&gt;Must be used judiciously — forces the function to be &lt;code&gt;inline&lt;/code&gt; and can cause code bloat if overused.&lt;/li&gt;
&lt;li&gt;Best suited for utility functions or framework code where type introspection and flexibility are genuinely needed.&lt;/li&gt;
&lt;/ol&gt;




&lt;h2&gt;
  
  
  Key Takeaways
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Inline
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;Substitutes the function body and lambdas directly at the call site, cutting down memory allocation and runtime overhead.&lt;/li&gt;
&lt;li&gt;Particularly effective when lambdas are used frequently, as it avoids the cost of object creation for each call.&lt;/li&gt;
&lt;li&gt;Unlocks the ability to use &lt;code&gt;reified&lt;/code&gt; generics, which is otherwise impossible in regular functions.&lt;/li&gt;
&lt;li&gt;Overusing it can lead to code bloat — the more places a large function is inlined, the larger the compiled output becomes.&lt;/li&gt;
&lt;li&gt;Apply it judiciously: best suited for small, frequently called higher-order functions rather than large or rarely used ones.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  reified
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;Allows access to generic type information at runtime, which is normally erased by the JVM.&lt;/li&gt;
&lt;li&gt;Makes type-based operations safer, cleaner, and more readable.&lt;/li&gt;
&lt;li&gt;Best suited for runtime reflection or type manipulation scenarios.&lt;/li&gt;
&lt;li&gt;Only works inside &lt;code&gt;inline&lt;/code&gt; functions — it cannot be used in regular generic programming.&lt;/li&gt;
&lt;/ol&gt;




&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;The &lt;code&gt;inline&lt;/code&gt; keyword and &lt;code&gt;reified&lt;/code&gt; generics are among Kotlin's most powerful yet nuanced features. When applied thoughtfully, they eliminate boilerplate, improve runtime performance, and enable type-safe operations that would otherwise require verbose workarounds. However, like any optimization tool, they come with trade-offs such as code bloat, design constraints, and limited applicability outside specific contexts. The key is knowing when to reach for them and when to step back. As you grow more comfortable with these features, you'll find they naturally slot into the right places in your codebase, making your Kotlin code not just more efficient, but more expressive and elegant.&lt;/p&gt;

</description>
      <category>kotlin</category>
      <category>reified</category>
      <category>jvm</category>
      <category>android</category>
    </item>
  </channel>
</rss>
