Skip to content

Commit b0bf78e

Browse files
Extension Function
1 parent 2543f6c commit b0bf78e

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

Extension Function Kotlin

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
Extension functions: These are the functions that helps us to extend the functionality
2+
of the class without getting into the code of that class
3+
i.e. you just have to call the function of the class.
4+
5+
Ex.
6+
7+
fun Int.triple(): Int {
8+
return this * 3
9+
}
10+
11+
fun main(args: Array<String>) {
12+
var result = 10.triple()
13+
println(result)
14+
}
15+
16+
In the above example, we have made one function triple(), which triples the value of an integer.
17+
So, in the main function, we have used the extension function calling to tripple the value passed i.e. 10 in our case.

0 commit comments

Comments
 (0)