Created
June 23, 2017 10:03
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is great, thank you. I was going to decompile the Kotlin to see what was going on, but you beat me to it 😄
Much appreciated!