23

Write extension functions for your own classes in Kotlin

 4 years ago
source link: https://blog.frankel.ch/write-extension-functions-own-classes-kotlin/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
A recent question on Kotlin’s Reddit came to my attention lately: 'Why is it bad to write extension functions for classes that you own?' One of the answer was that it was the opposite: it’s a good practice, and for several reasons. Among them were two very important ones that improve the design of one’s code: Able to call the function on a nullable. For a class with generic types, add a function that is only available when a specific type is used.

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK