본문 바로가기
[도서 정리] Android Development with Kotlin - Functions as First-Class Citizens Android Development with Kotlin - Functions as First-Class Citizens 이 정리글은 Kotlin in Action 책을 보고 실무에 Kotlin 을 사용하던 사람이 몰랐던 내용이나 remind 하고 싶은 내용을 위주로 정리한 글입니다.제대로 내용을 파악하시려면 책을 구매해서 읽어보세욤~ -아래와 같은 function 정의를 anonymous function 이라 부른다.val a: (Int) -> Int = fun(i: Int) = i * 2 -lambda 에서의 return 은 lambda 를 return 하는 것이 아닌 정의하며 호출하는 함수의 return 을 이야기한다.만약 lambda 를 return 하고 싶다면 아래와 같이 하면 된다.var aL.. 2018. 12. 14.
[도서 정리] Android Development with Kotlin - Classes and Objects Android Development with Kotlin - Classes and Objects 이 정리글은 Kotlin in Action 책을 보고 실무에 Kotlin 을 사용하던 사람이 몰랐던 내용이나 remind 하고 싶은 내용을 위주로 정리한 글입니다.제대로 내용을 파악하시려면 책을 구매해서 읽어보세욤~ -Kotlin 은 write-only property 는 지원하지 않는다. -Primary constructor 가 정의되어 있다면 secondary constructor 에서 반드시 불러줘야 한다. -Primary constructor 가 없는데 parent 가 non-empty constructor 를 가지고 있다면 그 녀석을 호출해주어야 한다. -class Fruit(name:String) .. 2018. 12. 13.
[도서 정리] Android Development with Kotlin - Playing with Functions Android Development with Kotlin - Playing with Functions 이 정리글은 Kotlin in Action 책을 보고 실무에 Kotlin 을 사용하던 사람이 몰랐던 내용이나 remind 하고 싶은 내용을 위주로 정리한 글입니다.제대로 내용을 파악하시려면 책을 구매해서 읽어보세욤~ -Function 과 Method 를 구분하는 논리..Function 은 이름을 가진 Code 조각.Method 는 class 와 연관되어진 function. member function 을 method 라 부른다. 논란의 여지는 있는데 Java 에는 Method 만 있다는 의견이 많다.일각에서는 static function 은 function 이라고 이야기하기도 한다. Kotlin 에서의 .. 2018. 12. 12.
[도서 정리] Android Development with Kotlin - Laying a Foundation Android Development with Kotlin - Laying a Foundation 이 정리글은 Kotlin in Action 책을 보고 실무에 Kotlin 을 사용하던 사람이 몰랐던 내용이나 remind 하고 싶은 내용을 위주로 정리한 글입니다.제대로 내용을 파악하시려면 책을 구매해서 읽어보세욤~ -Kotlin type inference 가 생기면서 가끔 무슨 type 으로 inference 가 되었는지 확인하고 싶을 수 있다."expression type” 기능을 사용하면 된다.[View] - [Expression Type] 을 사용하면 된다. ( 혹은 이 녀석을 지정한 단축키 ) 이는 generic type 에 대해서도 잘 작동한다. -var age: Short = 18 과 같이 적절한.. 2018. 12. 11.
[도서 정리] Android Development with Kotlin - Say hello to Kotlin [도서 정리] Android Development with Kotlin - Say hello to Kotlin 이 정리글은 Kotlin in Action 책을 보고 실무에 Kotlin 을 사용하던 사람이 몰랐던 내용이나 remind 하고 싶은 내용을 위주로 정리한 글입니다.제대로 내용을 파악하시려면 책을 구매해서 읽어보세욤~ -Android Studio 3.0 부터는 Kotlin plugin 이 따로 필요없다.처음부터 통합되어 설치되어 있다. -Tools -> Kotlin -> Configure Kotlin in Project 를 수행하면 자동으로 Project 에 코틀린 세팅이 된다. (굳!) -새로운 앱 프로젝트를 만들 때도 “Include Kotlin suport” 옵션을 체크하면 Kotlin 세팅.. 2018. 12. 10.
[Kotlin] Coroutine vs. thread (Light-weight thread 가 뭔 말이야?) [Kotlin] Coroutine vs. thread (Light-weight thread 가 뭔 말이야?) https://stackoverflow.com/questions/43021816/difference-between-thread-and-coroutine-in-kotlin -Coroutine 은 stackless, stackful 이렇게 두 가지 type 이 있다.Kotlin 은 stackless coroutine 이다. stackless 이기 떄문에 약간의 기능제한이 있다. -https://www.quora.com/Why-is-it-that-with-a-stackless-coroutine-only-the-top-level-routine-may-be-suspended Stackless corouti.. 2018. 11. 26.
[Kotlin] Coroutines tutorial - async code 쉽게 짜기 [Kotlin] Coroutines tutorial - async code 쉽게 짜기 https://github.com/Kotlin/kotlinx.coroutines/blob/master/coroutines-guide.md -Kotlin coroutines 는 async code 를 sync code 의 구조를 바꾸지 않고 짤 수 있게 도와준다. Coroutine Basics - modified내용이 바뀌어서 새로 정리하였습니다. -> Coroutine Basics ( 코루틴 기초 ) 예전 기록을 보고 싶으시면 아래 "더보기" 버튼을 눌러주세요!Hello World Coroutine -launch{ delay(1000L) println(“World!”)}println(“Hello,”)Thread.slee.. 2018. 11. 25.
[Kotlin] private constants [Kotlin] private constants Top-level 에 private 으로 정의한 variable 은 visibility 가 file 로 제한된다.그래서 아래와 같이 정의해서 쓰면 된다.private const val MY_CONST = “const” class AClass{ ...} Top-level 에 사용하고 싶지 않다면 class 안에 companion object 를 만들어 정의하는 방법도 있다.class AClass{companion object{private const val MY_CONST = "const"}} companion object, const val, java static final to kotlin, kotiln const declaration, kotlin co.. 2018. 10. 7.
[Kotlin] findViewById shows "type inference failed..." [Kotlin] findViewById shows "type inference failed..." 위와 같은 에러가 나는 이유는 findViewById 가 Android O 부터 Kotlin 에서 아래와 같이 정의되었기 떄문이다.public T findViewById(int id) { ...} 그래서 일반적인 기존 방식이 아닌 아래 방식으로 사용해야 한다.findViewById(R.id.textView) findviewbyid, Kotlin, kotlin findviewbyid, type inference failed, [Kotlin] findViewById shows "type inference failed..." 2018. 10. 6.
반응형