Skip to content

Instantly share code, notes, and snippets.

@npryce
Last active October 17, 2016 09:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save npryce/468555cb438c37070157827a8bacf529 to your computer and use it in GitHub Desktop.
Save npryce/468555cb438c37070157827a8bacf529 to your computer and use it in GitHub Desktop.
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