avatarGabriel Shanahan

Free AI web copilot to create summaries, insights and extended knowledge, download it at here

1394

Abstract

="https://readmedium.com/table-of-contents-c52573cfa291">Table of Contents</a> for all articles.</p></blockquote><p id="a96c">Interfaces in Kotlin can contain declarations of abstract methods, as well as method implementations. What makes them different from abstract classes is that interfaces cannot store state. They can have properties, but these need to be abstract or to provide accessor implementations.</p><p id="f97d">Unlike Java, no <code>default</code> keyword is necessary.</p> <figure id="4c79"> <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%2Fw7D066xKq&amp;display_name=Kotlin+Playground&amp;url=https%3A%2F%2Fpl.kotl.in%2Fw7D066xKq&amp;image=https%3A%2F%2Fplay.kotlinlang.org%2Fassets%2Fog-image.png&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=kotl" allowfullscreen="" frameborder="0" height="300" width="800"> </div> </div> </figure></iframe></div></div></figure><h1 id="c831">Properties</h1><p id="8b24">You can declare <i>synthetic</i> properties in interfaces. This means that a property declared in an interface can either be abstract, or it can provide implementations for accessors, but properties declared in interfaces can’t have b

Options

acking fields. Therefore, accessors declared in interfaces can’t reference them.</p> <figure id="7b76"> <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%2Fgwa2QZBgl&amp;display_name=Kotlin+Playground&amp;url=https%3A%2F%2Fpl.kotl.in%2Fgwa2QZBgl&amp;image=https%3A%2F%2Fplay.kotlinlang.org%2Fassets%2Fog-image.png&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=kotl" allowfullscreen="" frameborder="0" height="300" width="800"> </div> </div> </figure></iframe></div></div></figure><p id="5b93">Go back to <a href="https://readmedium.com/overriding-aad869ee3793">Overriding</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/visibility-modifiers-2137b71cddd0">Visibility Modifiers</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&amp;utm_medium=GabrielShanahan&amp;utm_campaign=KotlinPrimer&amp;utm_content=join-our-team&amp;utm_term=KotlinPrimer#pozice">Join me in Etnetera</a></figcaption></figure></article></body>

Interfaces

Interfaces in Kotlin, the absence of the default keyword, and rules for defining properties inside interfaces

— — — — — — — — — — — — — — —

THE CURRENT VERSION OF THIS ARTICLE IS PUBLISHED HERE.

— — — — — — — — — — — — — — —

Tags: #FYI

This article is part of the Kotlin Primer, an opinionated guide to the Kotlin language, which is indented to help facilitate Kotlin adoption inside Java-centric organizations. It was originally written as an organizational learning resource for Etnetera a.s. and I would like to express my sincere gratitude for their support.

It is recommended to read the Introduction before moving on. Check out the Table of Contents for all articles.

Interfaces in Kotlin can contain declarations of abstract methods, as well as method implementations. What makes them different from abstract classes is that interfaces cannot store state. They can have properties, but these need to be abstract or to provide accessor implementations.

Unlike Java, no default keyword is necessary.

Properties

You can declare synthetic properties in interfaces. This means that a property declared in an interface can either be abstract, or it can provide implementations for accessors, but properties declared in interfaces can’t have backing fields. Therefore, accessors declared in interfaces can’t reference them.

Go back to Overriding, jump to the Table of Contents, or continue to Visibility Modifiers.

Join me in Etnetera
Kotlin
Java
Programming
Interfaces
Object Oriented
Recommended from ReadMedium