Last active
October 9, 2018 14:10
-
-
Save gbzarelli/92ff30a41904ddbb425a8ccc2cd2c02f to your computer and use it in GitHub Desktop.
Sample Kotlin Functional Interface
This file contains hidden or 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
/** | |
* A interface funcional é declarada no método: | |
* myFuncionalInterface: (Int,String) -> Unit | |
* A interface acima tem como parametro um Int e uma String, ele é chamado como se fosse um método pelo proprio nome: | |
* myFuncionalInterface(1,"Sucesso") | |
*/ | |
fun methodFuncionalInterface(username: String, password: String, myFuncionalInterface: (Int,String) -> Unit) { | |
... | |
myFuncionalInterface(1,"Sucesso") | |
... | |
} | |
/** | |
* A interface funcional é passada no método que a recebe da seguinte maneira: | |
* {paramInt, paramString -> | |
* print(paramInt) | |
* print(paramString) | |
* } | |
* (Sua sintaxe é igual ao lambda.) | |
*/ | |
fun teste(){ | |
methodFuncionalInterface("username","pass", | |
{paramInt, paramString -> | |
print(paramInt) | |
print(paramString) | |
} | |
) | |
} | |
//Refêrencia: https://medium.com/google-developers/from-functional-java-to-functioning-kotlin-a4874a4a7a5 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment