Kotlin Higher-Order Functions
interface를 통해 간단한 연동이 필요할 경우
interface ExampleInterface
{
fun checkFun()
}
fun testFunction(example:ExampleInterface)
{
example.checkFun()
}
와 같이 사용 되던 부분을
fun testFunction(checkFun:()->Unit)
{
checkFun()
}
로 표현 할 수 있다.
비동기 처리와 같이 데이터 처리 후 결과를 리턴 할 경우 Higher-Oder Functions을 사용해
기존의 Interface를 사용 하지 않고 코드량을 줄여서 사용 할 수 있다.
---------- 설명 ---------
fun testFunction(checkFun:()->Unit)
checkFun => 함수명
() => 리턴값이 없을 경우 () 로 표현한다.
데이터를 넘겨야 할 경우 데이터 타입을 선언하면된다.
(String) ->. Unit 과 같은 형태
(String,Int) -> Unit 등..
Unit => 리턴값은 없기 때문에 Unit으로 처리
'Development > Android' 카테고리의 다른 글
Android Tool bar change icon (0) | 2019.07.26 |
---|---|
Android Studio 에서 JSON Kotlin Class 쉽게 만들기 (0) | 2019.05.31 |
Android GPS Turn On (0) | 2019.02.21 |
Android Soft Navigationbar visible check & android FullScreen Keyboard issue (0) | 2018.12.11 |
Google Samples Links (0) | 2018.06.26 |