Syntax

Kotlin Extension Function Syntax

In Kotlin, extension function: adds a function to an existing type — fun String.shout() = uppercase() + "!"

Quick Answer

Syntax
fun String.shout() = uppercase() + "!"
KotlinSyntax

Extension Function

Code example
fun String.shout() = uppercase() + "!"

Adds a function to an existing type.

Learn More

How to extension function in Kotlin

  1. Open your Kotlin file or editor.
  2. Copy the example, then replace its sample names and values for your code.

Kotlin Extension Function Syntax

Use fun String.shout() = uppercase() + "!".

Related Syntax References

Frequently asked questions

What is the Kotlin syntax for extension function?

Use this pattern: fun String.shout() = uppercase() + "!"

Can I copy this Kotlin code example?

Yes. Use Copy code and adapt the example to your program.

Is this Kotlin syntax different on Mac or Windows?

No. The language syntax is the same across operating systems.

Official source · How we verify