<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Muhammad Ali on Medium]]></title>
        <description><![CDATA[Stories by Muhammad Ali on Medium]]></description>
        <link>https://medium.com/@aligondal8750?source=rss-461e1f08afde------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*0C1Ki-VnqN1XSIwtb3QwZA.png</url>
            <title>Stories by Muhammad Ali on Medium</title>
            <link>https://medium.com/@aligondal8750?source=rss-461e1f08afde------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 30 Nov 2026 19:21:20 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@aligondal8750/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[What are Kapt and KSP?]]></title>
            <link>https://medium.com/@aligondal8750/what-are-kapt-and-ksp-b6b754b4a5a3?source=rss-461e1f08afde------2</link>
            <guid isPermaLink="false">https://medium.com/p/b6b754b4a5a3</guid>
            <category><![CDATA[kapt-vs-ksp]]></category>
            <category><![CDATA[kapt]]></category>
            <category><![CDATA[annotation-processor]]></category>
            <category><![CDATA[ksp]]></category>
            <category><![CDATA[annotations]]></category>
            <dc:creator><![CDATA[Muhammad Ali]]></dc:creator>
            <pubDate>Tue, 18 Mar 2025 20:54:59 GMT</pubDate>
            <atom:updated>2025-03-19T17:54:11.370Z</atom:updated>
            <content:encoded><![CDATA[<p>Whenever I implement libraries like <strong>Dagger Hilt, Room, </strong>or <strong>Retrofit</strong>, one question always comes to mind: Why do I need to put annotations in classes? <em>Why is there even a need to add annotations and include KAPT (Kotlin Annotation Processing Tool) and now KSP (Kotlin Symbol Processor) in the Gradle files?</em></p><p>These questions make me uncomfortable when using these libraries without fully understanding them.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*01NIjezquklA9e9JOzQCfg.png" /></figure><p>So, after googling my questions and doing research, opening multiple tabs to find my answers which clear the clouds above me. The answer to my first question is that all these libraries are built on top of <strong>Java</strong>. This means that behind the scenes when compiling the files or classes that use these libraries, the <strong>compiler has to generate alternative files</strong> for those classes and interfaces.</p><p>For example:</p><pre>// Dagger Hilt - Marks a class as a Hilt module<br>@Module<br>@InstallIn(SingletonComponent::class)<br>class AppModule {<br>@Provides<br>  fun provideSomething(): SomeDependency = SomeDependency()<br>}<br><br>// Room - Marks a class as a Room database<br>@Database(entities = [User::class], version = 1)<br>abstract class AppDatabase : RoomDatabase() {<br>  abstract fun userDao(): UserDao<br>}<br><br>// Retrofit - Marks an interface as a Retrofit API service<br>interface ApiService {<br>  @GET(&quot;users&quot;)<br>  suspend fun getUsers(): List&lt;User&gt;<br>}</pre><p>These generated files help the compiler process the code conveniently.</p><p>The generated files are called <strong>Java stub files</strong> (temporary files created at compile-time, which are automatically deleted after successful compilation).</p><h3>Why Do We Need Annotations?</h3><p><em>Just like Google Translate helps bridge the language barrier between English and German, annotation processing bridges the gap between Kotlin and Java. The compiler needs a way to “translate” Kotlin annotations into something Java-based libraries (like Dagger, Room, and Retrofit) can understand. It is where KAPT and KSP come in.</em></p><ul><li><em>The </em><strong><em>language barrier</em></strong><em> between </em><strong><em>English and German</em></strong><em> represents the </em><strong><em>gap</em></strong><em> between </em><strong><em>Kotlin and Java</em></strong><em> in annotation processing.</em></li><li><em>In this context, that </em><strong><em>marking process</em></strong><em> is called </em><strong><em>annotating files </em></strong><em>— it’s like adding a </em><strong><em>flag</em></strong><em> for the compiler to generate the required stubs for the annotated files.</em></li><li><em>The process of </em><strong><em>identifying text in a different language and translating it</em></strong><em> is similar to </em><strong><em>annotations marking files for the compiler</em></strong><em>. Hence, the compiler generated stubs for these files.</em></li><li><strong><em>Google Translate</em></strong><em> acts as the </em><strong><em>annotation processor</em></strong><em>, converting one language into another, just like </em><strong><em>KAPT or KSP</em></strong><em> converts annotated Kotlin code into Java-compatible stub files.</em></li></ul><h3>KAPT vs. KSP: Which One and Why?</h3><p>So, now we understand what annotations are and why we use them.</p><p>Previously, Kotlin provided <strong>KAPT</strong> (Kotlin Annotation Processing Tool) for this annotation processing. However, <strong>KAPT is a bit slower</strong> because it is written in <strong>Java</strong>, meaning it takes more time and generates more files, making it <strong>less efficient</strong>.</p><p>Due to KAPT’s inefficiency, a better solution was needed. In <strong>Kotlin 1.5.30, </strong>KSP (Kotlin Symbol Processing) was introduced.</p><p>That’s a wrap on how annotation processors work under the hood! By adopting KSP, you gain better performance, fewer generated files, and a more Kotlin-friendly development experience.</p><p>Stay curious, keep exploring, and always choose the right tools for the job!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b6b754b4a5a3" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>