https://kotlinlang.org/docs/reference/functions.html
javascript 의 prototype 을 생각하면 될듯 한 ?
어떠한 객체에 추가적인 구현이 필요할 경우 ?
아래의 코드는 Int 를 확장하여 shl 이라는 method 를 만든 예제
// Define extension to Int
infix fun Int.shl(x: Int): Int {
...
}
// call extension function using infix notation
1 shl 2
// is the same as
1.shl(2)
javascript 의 prototype 을 생각하면 될듯 한 ?
어떠한 객체에 추가적인 구현이 필요할 경우 ?
아래의 코드는 Int 를 확장하여 shl 이라는 method 를 만든 예제
// Define extension to Int
infix fun Int.shl(x: Int): Int {
...
}
// call extension function using infix notation
1 shl 2
// is the same as
1.shl(2)
'Android' 카테고리의 다른 글
코틀린 standard library (0) | 2017.07.07 |
---|---|
코틀린 typealias (0) | 2017.07.07 |
코틀린 default arguments (0) | 2017.07.07 |
코틀린 open class (0) | 2017.07.07 |
코틀린 single expression function (0) | 2017.07.07 |