Extension Functions in Kotlin

fun <class_name>.<extention_function>()
fun Int.isEven(): Boolean {
return when (this % 2) {
0 -> true
else -> false
}
}

val number = 8
println("${number.isEven()}")

--

--

--

19 Years Old | Pursing Android Development

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

Recommended from Medium

Data is taking to long to get back!

Functional Test Myopia

How to deal with technical debt?

Configure index rollover for AWS Elasticsearch indexes using Lambda function (with EFK)

Basic actions using Selenium in Python

😈TOP 7 Reasons Why A Developer Can Kiss His Productivity Goodbye✋

Counter App using Flutter with MobX

Code Smell in the design of your project

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
Alexander Portillo

Alexander Portillo

19 Years Old | Pursing Android Development

More from Medium

LiveData in Kotlin

Kotlin Cookbook 1

How and When to convert a Utility function in Kotlin to an Extension Function

Kotlin Collections & Operations