Android
-
[Kotlin] HashMapAndroid 2020. 12. 16. 00:43
fun main(args: Array){ val hashMap:HashMap = HashMap() //define empty hashmap hashMap.put(1,"Ajay") hashMap.put(3,"Vijay") hashMap.put(4,"Praveen") hashMap.put(2,"Ajay") println(".....traversing hashmap.......") for(key in hashMap.keys){ println("Element at key $key = ${hashMap[key]}") } } Output: .....traversing hashmap....... Element at key 1 = Ajay Element at key 2 = Ajay Element at key 3 = V..
-
[Kotlin] @JvmOverloadsAndroid 2020. 11. 6. 11:42
모든 경우의 오버로딩 메소드를 코틀린 컴파일러가 자동으로 생성 코틀린만 사용할 경우에는 사용할 필요가 없음 자바에서 코틀린 클래스나 함수를 자주 호출할 때 유용함 ex) 코틀린에서 @JvmOverloads 사용 @JvmOverloads fun test(a: String, b: Int = 0, c: String = "abc") { // } 실제는 아래처럼 생성됨 void test(String a, int b, String c) { } void test(String a, int b) { } void test(String a) { }
-
[Kotlin] Scoping Functions apply vs. with, let, also, and runAndroid 2020. 11. 4. 15:06
Here is the definition of all 5 functions: inline fun with(receiver: T, block: T.() -> R): R { return receiver.block() } inline fun T.also(block: (T) -> Unit): T { block(this) return this } inline fun T.apply(block: T.() -> Unit): T { block() return this } inline fun T.let(block: (T) -> R): R { return block(this) } inline fun T.run(block: T.() -> R): R { return block() } using apply val peter = ..