<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/"><channel><title>Kotlin-Library on afanasev.net</title><link>https://afanasev.net/categories/kotlin-library/</link><description>Recent content in Kotlin-Library on afanasev.net</description><generator>Hugo</generator><language>en-US</language><lastBuildDate>Tue, 13 Aug 2019 14:18:12 +0700</lastBuildDate><atom:link href="https://afanasev.net/categories/kotlin-library/feed.xml" rel="self" type="application/rss+xml"/><item><title>Sekret — risk-free toString() of Kotlin data class?</title><link>https://afanasev.net/kotlin-library/2019/08/13/sekret.html</link><pubDate>Tue, 13 Aug 2019 14:18:12 +0700</pubDate><guid>https://afanasev.net/kotlin-library/2019/08/13/sekret.html</guid><description>&lt;h2 id="problem"&gt;Problem&lt;/h2&gt;
&lt;p&gt;One of Kotlin&amp;rsquo;s most appreciated features is the data class. With a single keyword, the compiler automatically generates &lt;code&gt;equals&lt;/code&gt;, &lt;code&gt;hashCode&lt;/code&gt;, &lt;code&gt;copy&lt;/code&gt;, &lt;code&gt;componentN&lt;/code&gt;, and &lt;code&gt;toString&lt;/code&gt; — eliminating an entire category of boilerplate that Java developers had to write and maintain by hand. For domain objects, value types, and state containers, data classes are the obvious choice.&lt;/p&gt;
&lt;p&gt;The &lt;code&gt;toString&lt;/code&gt; function, in particular, is invaluable for debugging. When you log a data class instance, you get a complete, readable snapshot of its state: every field name and value, formatted cleanly. This is exactly what you want during development.&lt;/p&gt;</description></item><item><title>KSON — auto-generate GSON adapters for Kotlin data classes</title><link>https://afanasev.net/kotlin-library/2019/08/12/kson.html</link><pubDate>Mon, 12 Aug 2019 14:18:12 +0700</pubDate><guid>https://afanasev.net/kotlin-library/2019/08/12/kson.html</guid><description>&lt;p&gt;Kotlin data classes are an ideal fit for API response models. They are concise, immutable by default, and come with auto-generated &lt;code&gt;equals&lt;/code&gt;, &lt;code&gt;hashCode&lt;/code&gt;, &lt;code&gt;copy&lt;/code&gt;, and &lt;code&gt;toString&lt;/code&gt; — everything you need from a value object representing a network payload. Pairing them with GSON is natural and widely practiced across the Android ecosystem.&lt;/p&gt;
&lt;p&gt;However, there is a subtle but serious trap hiding in that combination — one that silently violates Kotlin&amp;rsquo;s type safety guarantees and can cause crashes that are difficult to reproduce and frustrating to diagnose.&lt;/p&gt;</description></item></channel></rss>