Created
October 3, 2017 18:09
-
-
Save tanmatra/3175320b60103e8d22808b629b4ebef5 to your computer and use it in GitHub Desktop.
Kotlin SAM conversions
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
import java.util.Date; | |
import java.util.function.Consumer; | |
public interface Caller | |
{ | |
void call(String id, Consumer<Integer> integerConsumer, Consumer<String> stringConsumer, Consumer<Date> dateConsumer); | |
} |
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 testCaller3(caller: Caller) { | |
val consumer1: Consumer<Int> = Consumer { int: Int -> println(int) } | |
val consumer2: Consumer<String> = Consumer { string: String -> println(string) } | |
val consumer3: Consumer<Date> = Consumer { date: Date -> println(date) } | |
val function1 = { int: Int -> println(int) } | |
val function2 = { string: String -> println(string) } | |
val function3 = { date: Date -> println(date) } | |
caller.call("id", consumer1, consumer2, consumer3) // OK | |
caller.call("id", function1, function2, function3) // OK | |
caller.call("id", consumer1, function2, function3) // Error | |
caller.call("id", consumer1, consumer2, function3) // Error | |
caller.call("id", function1, consumer2, consumer3) // Error | |
caller.call("id", function1, function2, consumer3) // Error | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment