tezvyn:

What is an extension function? Write a hasWhitespace extension for String.

Source: kotlinlang.orgintermediate

WHAT IT TESTS: Kotlin extensions are static dispatch, not true members. ANSWER OUTLINE: Explain receiverType.functionName adds behavior without inheritance; write hasWhitespace with any { it.isWhitespace() }. RED FLAG: Extensions modify classes or override.

WHAT IT TESTS: Whether you understand Kotlin extension functions as static dispatch sugar, not real class members. ANSWER OUTLINE: First, define them as behavior added without inheritance via receiverType.functionName syntax; second, stress they do not modify the underlying class and are resolved statically at compile time. Third, implement hasWhitespace with any { it.isWhitespace() } or a regex check. RED FLAG: Claiming extensions override superclass methods, are inherited, or modify third-party 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 an extension function? Write a hasWhitespace extension for String. · Tezvyn