Free AI web copilot to create summaries, insights and extended knowledge, download it at here
1245
Abstract
ir support.</p></blockquote><blockquote id="757e"><p>It is recommended to read the <a href="https://readmedium.com/introduction-2cc7eba631e2">Introduction</a> before moving on. Check out the <a href="https://readmedium.com/table-of-contents-c52573cfa291">Table of Contents</a> for all articles.</p></blockquote><p id="d7c0">When not specified, default getters and setters (i.e. <code>return field</code> and <code>field = value</code>) are automatically generated by the compiler. Kotlin also adds syntactic sugar that allows working with properties as if they were fields, so <code>obj.x</code> is actually <code>obj.getX()</code> and <code>obj.x = y</code> is actually <code>obj.setX(y)</code>. It is important to remember that <b>this is only syntactic sugar</b>, and it is the accessor functions that actually get called.</p><p id="4949">If you need to customize the accessors, use <code>get()</code> and/or <code>set()</code>:</p>
<figure id="0e05">
<div>
<div>
<img class="ratio" src="http://placehold.it/16x9">
<iframe class="" src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fpl.kotl.in%2FN00a8pi7n&display_name=Kotlin+Playground&url=https%3A%2F%
Options
2Fpl.kotl.in%2FN00a8pi7n&image=https%3A%2F%2Fplay.kotlinlang.org%2Fassets%2Fog-image.png&key=a19fcc184b9711e1b4764040d3dc5c07&type=text%2Fhtml&schema=kotl" allowfullscreen="" frameborder="0" height="300" width="800">
</div>
</div>
</figure></iframe></div></div></figure><p id="f3c4">Equipped with this knowledge, we can state the technical difference between properties defined using <code>val</code> or <code>var</code>: <code>val</code> doesn't generate a setter, while <code>var</code> does.</p><p id="e89a">Go back to <a href="https://readmedium.com/properties-introduction-fd98bc9c1056">Properties — Introduction</a>, jump to the <a href="https://readmedium.com/table-of-contents-c52573cfa291">Table of Contents</a>, or continue to <a href="https://readmedium.com/backing-fields-e0efd8ef6895">Backing Fields</a>.</p><figure id="8ecd"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*biBSB579iezsNvEQ_NMLBg.png"><figcaption><a href="https://www.etnetera.cz/prace-u-nas?utm_source=medium&utm_medium=GabrielShanahan&utm_campaign=KotlinPrimer&utm_content=join-our-team&utm_term=KotlinPrimer#pozice">Join me in Etnetera</a></figcaption></figure></article></body>