본문 바로가기
[Kotlin] Parcelable 을 쉽게 만들어보자 [Kotlin] Parcelable 을 쉽게 만들어보자 -Kotlin 1.1.4 버전부터 사용할 수 있는 기능입니다.Parcelable 로 만들고 싶은 녀석에 @Parcelize 라는 annotation 만 붙여주면 되죠. -// build.gradleapply plugin: "org.jetbrains.kotlin.android.extensions"androidExtensions { experimental = true // 아직 실험단계라 이 flag 를 주어야 합니다.} // kotlin@Parcelizeclass User(val firstName: String, val lastName: String) : Parcelable 위와 같이 쓰면, 우리가 생각하는 기본적 Parcelable 구현이 완성됩니다.. 2018. 4. 1.
[Kotlin] initializer 이야기 [Kotlin] initializer 이야기 https://medium.com/keepsafe-engineering/an-in-depth-look-at-kotlins-initializers-a0420fcbf546 -constructor, initializer 등이 있을 때 적용되는 순서를 아는 것이 좋다. 먼저 constructor 의 default argument 가 가장 먼저 적용된다.그 다음 property initializer 와 init block 이 수행된다. 이 때 수행 순서는 top-to-bottom 으로 정의된 순서대로 수행된다.그 다음에 constructor 가 수행된다. -open class Parent { private val a = println("Parent.a") constru.. 2018. 1. 19.
[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] Kotlin 의 숨겨진 비용 #2 [Kotlin] Kotlin 의 숨겨진 비용 #2 https://medium.com/@BladeCoder/exploring-kotlins-hidden-costs-part-2-324a4a50b70 Local functions -local function 의 limit 은 inline 으로 정의될 수 없다는 것 ( 글 쓴 당시까지는, 현재버전에서 꼭 체크해보라 ).그리고 local function 을 가지고 있는 녀석도 inline 이 될 수 없다.fun someMth(a: Int): Int { fun sumSquare(b: Int) = (a+b) * (a+b) return sumSquare(1) + sumSqaure(2)} local function 은 Function object 로 바뀐다.public .. 2018. 1. 17.
[Kotlin] Kotlin 의 숨겨진 비용 #1 [Kotlin] Kotlin 의 숨겨진 비용 #1 https://medium.com/@BladeCoder/exploring-kotlins-hidden-costs-part-1-fbb9935d9b62 -“With great power comes great responsibility” 를 기억해야 한다.( 간단한 코드를 짜는 대신 대가가 있다는 얘기다 ) -Kotlin bytecode inspector 를 사용하면 Kotlin 코드가 어떻게 bytecode 로 변환되는지 볼 수 있다.Android studio plugin 으로 접할 수 있다.이를 보면 primitive type 의 boxing, code 에서 보이지 않는 기타 object 들의 instantiation, 그리고 각종 추가 method 들의 추.. 2018. 1. 16.
[Kotlin] 장점, 단점, 그리고 아쉬운 점 이야기 [Kotlin] 장점, 단점, 그리고 아쉬운 점 이야기 https://medium.com/keepsafe-engineering/lessons-from-converting-an-app-to-100-kotlin-68984a05dcb6https://medium.com/keepsafe-engineering/kotlin-the-good-the-bad-and-the-ugly-bf5f09b87e6f -위 링크의 글을 쓴 필자는 마켓에 출시된 Java 로 되어 있는 앱을 Kotlin 으로 전환했다.많은 사람들이 Kotlin lib 때문에 dex method limit 이 걸릴 것을 걱정하지만,실제 converting 후 proguard 적용시 method count 는 10% 줄어들고, code line 은 30% 줄.. 2018. 1. 15.
[Kotlin] Kotlin 은 Compile time 이 느리다는데.. 사실일까? [Kotlin] Kotlin 은 Compile time 이 느리다는데.. 사실일까? https://medium.com/keepsafe-engineering/kotlin-vs-java-compilation-speed-e6c174b39b5d -위 글을 쓴 필자는 Java base 로 되어 있는 출시된 앱을 전부 Kotlin 으로 전환하여 자신만의 Compile time 을 측정해보았다. -테스트 환경 및 조건 #1 빌드는 총 10번 연속으로 돌려서 평균값 산출Hardware 는 i7-6000 3.4GHz, 32G DDR4, Samsung 850 Pro SSD, Gradle 2.14.1 빌드시마다 매번 clean build or notGradle daemon 사용 or not코드 변경 유무 -Clean bui.. 2017. 9. 26.
[Kotlin Tutorial] The Kotlin ecosystem [Kotlin Tutorial] The Kotlin ecosystem 참조 : Kotlin in action -비록 Kotlin 의 역사는 오래되지 않았지만, 이미 lib, framework, tool 들로 구성된 ecosystem 이 잘 마련되었다.그리고 그들은 대부분 외부 개발 커뮤니티에서 개발된 것이다. https://kotlin.link/ 여기 가면 많은 정보를 얻을 수 있다. -Kotlin 은 Java 와 함께 사용가능하기 떄문에,lib 검색할 떄 Kotlin lib 으로 한정지을 필요가 없다. 당연히 Java lib 을 가져다 써도 된다. 1. Testing -JUnit, TestNG 도 좋지만, 아래 DSL 들은 더 표현력이 풍부하다. KotlinTest https://github.com/k.. 2017. 9. 22.
[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.
반응형