Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Another Kotlin string pitfalls

Don't write an extension method that implement the plus operator with String arguments. If you forget to import it, the code will compile, but use string append instead.

public final class String {
  ... public final operator fun plus(other: kotlin.Any?): kotlin.String { /* compiled code */ }

So, always write a conversion function from String to your own type, then implement + on that type.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment