Kotlin - Extension
In this chapter, we can learn Kotlin - Extension.
You can add without do away with inheriting or editing them
Kotlin lets in to outline a technique out of doors of the principle magnificence
Let's see following example how the extension is applied at the practical level.
class Alien var talents : String = "null" a laugh printMySkills() print(competencies) a laugh essential(args: ArrayIn the above example, we don’t have any approach inner “Alien” elegance named as "addMySkills()" Output
) var a1 = Alien() a1.Abilties = "Play" //a1.PrintMySkills() var a2 = Alien() a2.Capabilities = "Read" //a2.PrintMySkills() var a3 = Alien() a3.Skills = a1.AddMySkills(a2) a3.PrintMySkills() fun Alien.AddMySkills(a:Alien):String var a4 = Alien() a4.Skills = this.Capabilities + " " +a.Talents go back a4.Capabilities
Using this mechanism, we will create an item of a category internal a factory technique and later we can simply name that method the use of the reference of the magnificence name. In the subsequent instance, we will create a “partner item”.
amusing predominant(args: ArrayThe above piece of code will yield the following output inside the browser.
) println("Hello!!!"+A.Show()) magnificence A associate object a laugh display():String return("You are mastering Kotlin from Welookups.Com")
You are getting to know Kotlin from Welookups.Com