본문 바로가기
[도서 정리] Android Development with Kotlin - Extension Functions and Properties Android Development with Kotlin - Extension Functions and Properties 이 정리글은 Kotlin in Action 책을 보고 실무에 Kotlin 을 사용하던 사람이 몰랐던 내용이나 remind 하고 싶은 내용을 위주로 정리한 글입니다.제대로 내용을 파악하시려면 책을 구매해서 읽어보세욤~ -extension function 들도 inline 가능하다. -extension function 과 같은 이름의 member function 이 있다면,항상 member function 이 우선순위를 갖는다.여기서 member function 이라 하면 super class 에 있는 member function 들도 해당한다. 이 말은 extension functio.. 2018. 12. 16.
[Kotlin] Kotlin 의 숨겨진 비용 #3 [Kotlin] Kotlin 의 숨겨진 비용 #3 https://medium.com/@BladeCoder/exploring-kotlins-hidden-costs-part-3-3bf6e0dbf0a4 Delegated property -class Example{ var p: String by Delegate()} property 에 delegate 를 사용할 경우에 해당 delegate 는 operator function 인 getValue 와 setValue 를 구현해야 한다.해당 function 들은 object instance 와 property metadata 를 받는다. public final class Example{ @NonNull private final Delegate p$delegate =.. 2018. 1. 18.
[Kotlin Tutorial] Documenting Kotlin code [Kotlin Tutorial] Documenting Kotlin code 출처 : Kotlin in action 1. Writing Kotlin documentation comments -Java 의 Javadoc 만들 때와 비슷하다.Kotlin 의 것은 KDoc 이라 부른다. -KDoc 은 /** 로 시작하고 tag 는 마찬가지로 @ 로 시작한다.Javadoc 과의 가장 큰 차이가 있다면 HTML 대신 Markdown 을 사용한다는 것이다./** * Calculates the sum of two numbers, [a] and [b] */fun sum(a: Int, b: Int) = a+b 정의를 참조하려면 [ ] 안에 이름을 넣어주면 된다. cf) Markdown 은 text-to-HTML conve.. 2017. 9. 20.
[Kotlin Tutorial] DSL construction - Chap 11. [Kotlin Tutorial] DSL construction - Chap 11. 참조 : Kotlin in action 11.1. From APIs to DSLs -DSL 을 작성하기 전에 생각해봐야 할 것이 있다. 우리의 (Kotlin?) 궁극적 목표는 가독성과 유지보수성을 최대로 늘리는 것.그것은 곧 좋은 API 를 설계하는 것으로 이어진다. 그렇다면 API 가 clean 하다는 것은 무슨 의미일까?1. 사용자가 읽기 좋은 것. 그것은 name 과 concept 을 잘 잡는 것이다.2. 의미없는 syntax 는 빼고, 최소한의 코드로 code 가 읽기 좋은 것. -Kotlin 에서는 clean API 를 위해서 extension function, infix calls, lambda syntax sh.. 2017. 9. 14.
[Kotlin Tutorial] Annotation 과 Reflection #1 - Chap 10. Annotations and reflection [Kotlin Tutorial] Annotation 과 Reflection #1 - Chap 10. Annotations and reflection 참조 : Kotlin in action 10.1. Declaring and applying annotations. 10.1.1. Applying annotations -Annotation 사용법은 Java 와 동일하다. @ 를 prefix 로 하고 annotation name 을 써주면 된다. -@Deprecated 의 경우 Kotlin 은 Java 의 것에서 향상되었다.replaceWith parameter 가 추가되어, 새로운 version 의 API 에 연결될 수 있다.@Deprecated(“Use removeAt(index) instead.”, Rep.. 2017. 9. 7.
[Kotlin Tutorial] 한 차원 높은 함수 : 람다를 parameter 와 return value 로 - Chap8. Higher-order functions: lambdas as parameters and return values [Kotlin Tutorial] 한 차원 높은 함수 : 람다를 parameter 와 return value 로 - Chap8. Higher-order functions: lambdas as parameters and return values 참조 : Kotlin in action 8.1. Declaring higher-order functions -Higher-order function 이란 argument 와 return 으로 다른 function 을 갖는 것을 의미한다.Kotlin 에서는 function 이 lambda 나 function reference 로 표시된다. 8.1.1. Function types -val sum = { x:Int, y:Int -> x+y }val action = { pr.. 2017. 8. 31.
[Kotlin Tutorial] Kotlin 의 Type system #2 [Kotlin Tutorial] Kotlin 의 Type system #2 참조 : Kotlin in action 6.2. Primitive and other basic types 6.2.1. Primitive types: Int, Boolean, and more -Kotlin 은 primitive type 과 wrapper type 을 구분하지 않는다. -그렇다면 Int 가 object 라면 Kotlin 은 모든 primitive type 을 실제로 object 로 만드는가?당연히 그렇게 안 했다.compiler 가 대부분의 Int type 을 Java 의 primitive type 으로 변형시킨다.generic, collection 등은 원래 Java 의 Integer 형태만 담을 수 있으므로 이 경.. 2017. 8. 22.
[Kotlin Tutorial] 람다로 프로그래밍 하기 - Chap5. Programming with Lambdas [Kotlin Tutorial] 람다로 프로그래밍 하기 - Chap5. Programming with Lambdas 참조 : Kotlin in Action 5.1. Lambda expressions and member references 5.1.1. Introduction to lambdas : blocks of code as function parameters 5.1.2. Lambdas and collections -val people = listOf(Person(“Alice”, 29), Person(“Bob”, 31))println( people.maxBy{ it.age } ) // function 을 argument 로 받는다. { } 는 lambda syntax lambda 가 단순 functio.. 2017. 8. 16.
[Kotlin Tutorial] 클래스, objects, 그리고 인터페이스 #2 [Kotlin Tutorial] 클래스, objects, 그리고 인터페이스 #2 참조 : Kotlin in Action 4.3. Compiler-generated methods: Data classes and Class delegation 4.3.1. Universal object methods -Java 에서 == 는 primitive 나 object 의 reference 를 비교하는 것.Kotlin 에서는 == 가 기본비교이다. equals 를 호출해서 비교한다.그럼 Java 에서의 == 는? === 로 대체된다. 4.3.2. Data classes: autogenerated implementations of universal methods -data class Client(val name: Stri.. 2017. 8. 14.
반응형