Created
April 30, 2024 10:46
-
-
Save prasanthperumal92/25d94bd657130cdc85ba962cae76f070 to your computer and use it in GitHub Desktop.
A goofy sample on why infix keyword is a game changer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
open class Animal{ | |
infix fun has(value:Int):Animal{ | |
return this | |
} | |
infix fun legs(value:Animal):Animal{ | |
return this | |
} | |
infix fun a(value:Any):Animal{ | |
return this | |
} | |
} | |
object and: Animal() | |
object tail: Animal() | |
fun main(){ | |
val dog = Animal() | |
dog has 4 legs and a tail | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment