Last active
June 11, 2017 15:51
-
-
Save ReneeVandervelde/23c3df246763cd68d1d64c0087e9f822 to your computer and use it in GitHub Desktop.
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
interface KotlinConsumer<T> { | |
fun accept(value: T) | |
} | |
class KotlinObservable<T> { | |
fun subscribe(onNext: KotlinConsumer<T>) {} | |
} | |
class Test { | |
fun main() { | |
// FAILS: Type Mismatch: inferred type is KFunction1<@ParameterName String, Unit> but KotlinConsumer<String> was expected | |
KotlinObservable<String>().subscribe(this::stringConsumer) | |
// FAILS: Type mismatch: inferred type is () -> ??? but KotlinConsumer<String> was expected | |
KotlinObservable<String>().subscribe({ println(it) }) | |
// Works: Anonymous Implementation of the class | |
KotlinObservable<String>().subscribe(object: KotlinConsumer<String> { | |
override fun accept(value: String) { println(value) } | |
}) | |
} | |
// I want to use this method, but can't | |
fun stringConsumer(value: String) { | |
println(value) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment