Kotlin Extension Property

This blog was originally posted at https://agrawalsuneet.github.io/blogs/kotlin-extension-property/ and reposted on Medium on 13th Sept 2020.

Is it even possible?

Can we add a property/variable as an extension to an existing class?

class Temperature(var tempInCelsius: Float)
var Temperature.tempInFahrenheit: Float
get() = (tempInCelsius * 9 / 5) + 32
set(value) {
tempInCelsius = (value - 32) * 5 / 9

Please continue reading at https://agrawalsuneet.github.io/blogs/kotlin-extension-property/





Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

How to integrate google mobile ads in flutter app

XML Namespaces & Android Studio

Don’t get confused on delay & Thread.sleep() in Kotlin Coroutines

Text Recognition and Translation Demo Application Part 1

Android-10: How to send a customize protected broadcast from system

Creating Jetpack Compose Navigation and Submitting Arguments.

Integrate the Sound Detection feature using Huawei ML Kit in Android (Kotlin)

Nested RecyclerView and DataBinding

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Suneet Agrawal

Suneet Agrawal


More from Medium

Extension Functions in Kotlin

Null Safety in Kotlin

Kotlin Cookbook 1

Unable to load io.netty.resolver.dns.macos.MacOSDnsServerAddressStreamProvider