목록Mobile (128)
Hanbit the Developer
Kotlin Documentation 시리즈에 대해 Category: Concepts 문서 링크: https://kotlinlang.org/docs/annotations.html 어노테이션은 메타 데이터를 코드에 붙일 수 있는 수단이다. 어노테이션을 정의하기 위해 annotation 구분자를 클래스 앞에 붙인다. annotation class Fancy Additional attributes of the annotation: @Target: 어떤 유형에 어노테이션이 붙을 수 있는지를 명시한다.(클래스, 함수, 프로퍼티, 표현식) @Retention: 주석이 컴파일된 클래스 파일에 저장되는지 여부, 런타임에 리플랙션을 통해 표시되어야 하는지 여부를 결정한다.(기본적으로 양쪽 모두 참임) @Repeatabl..
Kotlin Documentation 시리즈에 대해 Category: Concepts 문서 링크: https://kotlinlang.org/docs/async-programming.html Threading 비용이 큼 제한된 개수 항상 쓰레드가 available한 게 아님 사용하기 어려움: 쓰레드 디버깅, race condition 등 Callbacks fun postItem(item: Item) { preparePostAsync { token -> submitPostAsync(token, item) { post -> processPost(post) } } } fun preparePostAsync(callback: (Token) -> Unit) { // make request and return imme..
Kotlin Documentation 시리즈에 대해 Category: Concepts 문서 링크: https://kotlinlang.org/docs/equality.html Structural equality: == Referential equality: === Structural equality a == b는 다음 코드로 번역된다: a?.equals(b) ?: (b === null) equals 함수로 contents(주소값이 아니라)를 비교하며, elvis 연산자를 통해 a가 null인 경우 b 또한 null인지 체크한다. equals(other: Any?): Boolean을 override함으로써 ==을 커스터마이징 할 수 있다. Referential equality 주소 체크. primitive의..
Kotlin Documentation Category: Concepts 문서 링크: https://kotlinlang.org/docs/null-safety.html Java에서 NPE 문제가 가장 많이 일어나는 문제 중 하나이다. Kotlin에서는 다음의 경우 NPE가 발생한다. throw NullPointerException() !!의 부적절한 사용 constructor에서 초기화되지 않은 this를 사용한 경우 Elvis operator ?:를 통한 null 처리: fun foo(node: Node): String? { val parent = node.getParent() ?: return null val name = node.getName() ?: throw IllegalArgumentExcepti..
Kotlin Documentation 시리즈에 대해 Category: Concepts 문서 링크: https://kotlinlang.org/docs/control-flow.html Returns and jumps Break and continue labels loop@ for (i in 1..100) { for (j in 1..100) { if (...) break@loop } } fun foo() { listOf(1, 2, 3, 4, 5).forEach lit@{ if (it == 3) return@lit // local return to the caller of the lambda - the forEach loop print(it) } print(" done with explicit label") }..
Kotlin Documentation 시리즈에 대해 Category: Concepts 문서 링크: https://kotlinlang.org/docs/basic-types.html *Kotlin은 Java였다면 primitive로 표현될 수 있는 값을 포함하여, 모두 객체로 취급한다.(Int, Double, Boolean) 이를 통해 일관성있고 널 세이프티하며 각 타입들에 대해 추가 기능들을 제공할 수 있다. 다만 이렇게 함으로써 발생하는 성능 저하 문제를 최소화하기 위해 boxing, unboxing을 이용한다. 코틀린 컴파일러가 각 상황에 맞게 연산들을 boxing, unboxing하기 때문에 퍼포먼스 차이는 무시할만하다.(ChatGPT) Numbers 타입 추론: 명시하지 않는 경우 컴파일러가 값으로..
https://kotlinlang.org/docs/home.html Kotlin Docs | Kotlin kotlinlang.org 개인적으로 Kotlin 언어 자체에 대한 공부가 부족한 것을 느껴 공식 문서를 정리하였으며, 이렇게 정리한 내용들을 업로드할 예정입니다. 오역이나 잘못 이해하여 작성한 정보가 있을 수 있으며, 제가 생각했을 때 당연한 내용, 매우 지엽적인 내용, Experimental, 불필요한 내용 등은 필터링하였습니다.
![](http://i1.daumcdn.net/thumb/C150x150/?fname=https://blog.kakaocdn.net/dn/dWDPwO/btr2PyTKASe/VhBnG7EmryKDeLKY5fKY80/img.png)
KTS and version catalog make our gradle file clear. And KTS's mainly used in modern android projects like Sunflower, nowinandroid. I used them to clear my gradle files and to practice Kotlin DSL. Let's see below images. The left one is my old gradle file, and the right one is the new one. This article covers how I migrated gradle files using KTS, version catalog. Migrating to KTS 1. Rename gradl..
![](http://i1.daumcdn.net/thumb/C150x150/?fname=https://blog.kakaocdn.net/dn/ccQIBJ/btr0qXKrkWf/eutJMG9DYG79BbdMYNvDRK/img.png)
Using test rules can help you write more efficient and effective tests, and can save you time by automating common testing tasks. And @Rule annotation is used to declare the test rule in JUnit. But in sunflower created by Google Android, @get:Rule is used instead of @Rule. In Kotlin, properties are compiled to getter and setter in Java, rather than public fields. So we need to apply the @Rule an..
![](http://i1.daumcdn.net/thumb/C150x150/?fname=https://blog.kakaocdn.net/dn/17mbN/btrZbO7xRk1/LTTw2eMClL1D6OW4MlpJe1/img.gif)
I released FiveStarsView which is a custom view for a touchable star rating view with customizable stars. With FiveStarsView, you can draw a custom view with touchable five stars, apply Two-way data binding to the view, and modify the image, color, size, and the like of those stars. And I'd like to talk about the contents below: How the custom view's implemented Two-way data binding with custom ..