tezvyn:

What is a Kotlin extension function? Write one for String.

Source: kotlinlang.orgintermediate

Tests your grasp of adding functionality to existing classes without inheritance. A great answer defines it as syntactic sugar over static methods, explains its use for third-party code, then implements the requested `String.hasWhitespace` function.

This tests your understanding of adding functionality to existing classes without inheritance. A strong answer first defines extension functions as syntactic sugar for static utility methods, not true class modification. Then, it explains their value for extending third-party library classes you can't change. Finally, it provides a concise implementation of `String.hasWhitespace`, like `fun String.hasWhitespace(): Boolean = any { it.isWhitespace() }`. A major red flag is claiming that extensions actually modify the original class's bytecode.

Read the original → kotlinlang.org

Get five bites like this every day.

Tezvyn delivers a daily feed of 60-second tech bites with quizzes to lock in what you learn.

What is a Kotlin extension function? Write one for String. · Tezvyn