Skip to content

Instantly share code, notes, and snippets.

View ReneeVandervelde's full-sized avatar
🌻
Keeping software in full bloom

Renee Vandervelde ReneeVandervelde

🌻
Keeping software in full bloom
View GitHub Profile
@Deprecated(
message = “Tell me what Foo is!”,
replaceWith = ReplaceWith(“newHotness(foo, bar)”)
)
fun oldAndBusted(bar: String) {}
@Deprecated(
message = “I forgot about Foo!”,
replaceWith = ReplaceWith(“newHotness(DEFAULT, bar)”, “acme.sandbox.foo.DEFAULT”)
)
fun oldAndBusted(bar: String) {}
@Deprecated(
message = “I wrote this backwards”,
replaceWith = ReplaceWith(“newHotness(foo, bar)”)
)
fun oldAndBusted(bar: String, foo: String) {}
@Deprecated(
message = “Use something different”,
replaceWith = ReplaceWith(“newHotness()”)
)
fun oldAndBusted() {}
import io.reactivex.Observable
import io.reactivex.functions.Consumer
class Foo {
fun main() {
Observable.just("foo").subscribe(this::stringConsumer, this::errorConsumer)
}
fun stringConsumer(value: String) { TODO() }
fun errorConsumer(error: Throwable) { TODO() }
import io.reactivex.Observable
import io.reactivex.functions.Consumer
class MyErrorHandler : Consumer<Throwable> {
override fun accept(t: Throwable?) { TODO() }
}
class Foo {
fun main() {
val errorHandler = MyErrorHandler()
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
import io.reactivex.Observable
import io.reactivex.functions.Consumer
class Foo {
fun main() {
Observable.just("foo", "bar").subscribe(this::stringConsumer)
}
fun stringConsumer(value: String) {
println(value)
fun setOnClickListener(listener: (view: View) -> Unit) {
// ...
}
fun main() {
setOnClickListener { it.bringToFront() }
setOnClickListener(this::test)
}
fun test(view: View) {
fun setOnClickListener(listener: (view: View) -> Unit) {
// ...
}