본문 바로가기
[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] Building Kotlin projects [Kotlin Tutorial] Building Kotlin projects 참조 : Kotlin in action 1. Building Kotlin code with gradle -Kotlin 을 사용하는데 추천되는 build system 은 gradle 이다.gradle 은 incremental build 를 사용해서 빌드 속도도 빠르게 할 수 있고,gadle daemon 이 있어 build process 도 오래 살아있고, 기타 고급 기술들이 들어가 있다. cf) incremental build 는 빌드된 구성 요소 중 최신 상태인 구성 요소는 다시 빌드하지 않는 것을 이야기한다.즉 빌드된 적 없는 대상이나 만료된 대상만 다시 빌드하는 빌드방식을 incremental build 라 부른다. -Gra.. 2017. 9. 18.
[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] Generics - Chap9. Generics 참조 : Kotlin in action 9.1. Generic type parameters -Java 와 기본적으로 generic 사용법은 동일하다. -Type Inference 는 가능하지만 명시적으로 써야 하는 케이스도 있다.val authors = listOf(“Dmitry”, “Svetlana”) // type inference 가능 val readers : MutableList = mutableListOf() // type inference 불가능, 명시적 선언val readers = mutableListOf() -Kotlin 에서는 raw type generic 을 사용할 수 없다. ( Java 로 치자면 그냥 List ) 9.1.1. Generic functions and properties.. 2017. 9. 5.
[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] Operator overload 와 convention #1 - Chap7. Operator overloading and other conventions [Kotlin Tutorial] Operator overload 와 convention #1 - Chap7. Operator overloading and other conventions 참조 : Kotlin in action -Java 에는 특정 class 에 결속되어 있는 언어적 기능이 있다.예를 들어 Iterable 를 구현하면 for loop 에서 쓸 수 있고, AutoCloseable 을 구현하면 try-with-resources 에서 사용할 수 있다. Kotlin 도 비슷한 것들이 있다.그러나 specific type 에 결속된 것이 아니라 specific name 에 결속되는 기능들이 있다.예를 들어 plus 라는 이름으로 class 에 function 을 추가하면, + operator 를 해.. 2017. 8. 24.
[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] Kotlin 의 Type system - Chap6. The Kotlin type system [Kotlin Tutorial] Kotlin 의 Type system - Chap6. The Kotlin type system 출처 : Kotlin in action 6.1. Nullability 6.1.1. Nullable types -Kotlin 은 nullable types 를 지원한다.nullable type 이라는 것은 어떤 variable 이 null 을 가질 수 있는지를 명시하는 것이다. -nullable 하지 않은 곳에 null 을 넣으면 compile error 가 난다.기본 type 은 nullable 하지 않으며, nullable 을 만드려면 type 뒤에 ? 를 붙여주면 된다.어떤 타입이든 뒤에 ? 를 붙여줄 수 있다.fun strLenSafe(s: String?) = … 6.1.2.. 2017. 8. 18.
반응형