Free AI web copilot to create summaries, insights and extended knowledge, download it at here
1602
Abstract
nal interface, or a Single Abstract Method (SAM) interface. The functional interface can have several non-abstract members but only one abstract member.</p>
<figure id="4072">
<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%2FStLgcu-VK&display_name=Kotlin+Playground&url=https%3A%2F%2Fpl.kotl.in%2FStLgcu-VK&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="f4c6">Interfaces such as this one are basically equivalent to lambda functions sharing the same signature as the abstract member. Kotlin allows this for interfaces marked with the <code>fun</code> keyword.</p>
<figure id="ca7f">
<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%2FVR-f1ON2o&display_name=Kotlin+Playground&url=https%3A%2F%2Fpl.kotl.in%2FVR-f1ON2o&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><
Options
/iframe></div></div></figure><p id="fc70">If you’re curious as to why the decision was made to make a special keyword necessary, and interesting view was given by Pavel Talanov in the <a href="https://youtrack.jetbrains.com/issue/KT-7770#focus=Comments-27-997598.0-0">corresponding issue</a>:</p><blockquote id="03a2"><p><i>SAM are mainly a convenient automatic wrapper for the code that you cannot change. If you’re designing an API in Kotlin you can (and should) make a choice: Is this entity just a function or a separate class that can evolve into something more complex.</i></p></blockquote><p id="fa69">In other words, <a href="https://readmedium.com/preface-a65cb535d122#39fa">communicate intent</a>.</p><p id="734c">The same functionality is <a href="https://kotlinlang.org/docs/java-interop.html#sam-conversions">available</a> by default when calling Java classes.</p><p id="c99c">Go back to <a href="https://readmedium.com/inline-value-classes-773093aece23">Inline (Value) Classes</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/extension-functions-motivation-a55abc644c5a">Extension Functions: Introduction</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>