Skip to content

Instantly share code, notes, and snippets.

@ditn
Created June 23, 2017 10:03
Show Gist options
  • Save ditn/32ccf5e63e112c95eeff63871db79366 to your computer and use it in GitHub Desktop.
Save ditn/32ccf5e63e112c95eeff63871db79366 to your computer and use it in GitHub Desktop.
An example of a gotcha that I found whilst working with method references in RxJava/Kotlin
fun printString(string: String) = println(string)
/**
* Prints successfully
*/
Observable.just("Test string")
.doOnNext{ printString(it) }
.subscribe()
/**
* Prints successfully
*/
Observable.just("Test string")
.doOnNext(this::printString)
.subscribe()
/**
* Does not print
*/
Observable.just("Test string")
.doOnNext { this::printString }
.subscribe()
@lmller
Copy link

lmller commented Jun 23, 2017

You're welcome! :-)

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