목록Kotlin (30)
Foggy day

class KotlinPlayGroundActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_kotlin_play_ground) introduce() hungry.start() age() //GlobalScope.launch는 thread와 비슷한 기능 // launch는 코루틴의 빌더이며 빌더를 사용하기 위해서는 scope가 필요하다 // GlobalScope는 scope중의 하나 //delay는 suspend 함수로 일시중단같은 개념, suspend 함수는 scope 안에서거나 백그..
class KotlinPlayGroundActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_kotlin_play_ground) val human = Human("Man", 30, "jerome") val (sex, age, name) = human println("sex : $sex, age : $age, name : $name") ///// sex : Man, age : 30, name : jerome ////// } } data class Human( val sex: String,..

val value = object { val x = 0 val y = 10 val z = 20 } println("value x : ${value.x}, y : ${value.y}, z : ${value.z}") //// value x : 0, y : 10, z : 20 val school: School = object : School(3), ClassGroup { override val students: Int get() = super.students override fun OnJoinClassGroup(classNumber: Int) { super.OnJoinClassGroup(3) } } println("school.students ${school.students}") //// school.stud..

val list = listOf(3, 4, 5, 6, 7, 8, 9, 10) val value = 12 val result = when (value) { in list -> "value is in the list" in 1..10 -> "It is in the range A" in 10..20 -> "It is in the range B" else -> "none fo the above" } println("result : $result") //result : It is in the range B val array = arrayOf("A", "B", "C", "D") for (i in array.indices) { println("i : ${array[i]}") } // A, B, C, D for ((i..

val intSrc = Observable.just(1, 2, 3) intSrc.subscribe(::println) val strSrc = intSrc.map { value -> value * 10 } strSrc.subscribe(::println) val src = Observable.just("A", "B", "C", "D") src.flatMap { s -> Observable.just(s + 2, s + 3) } src.subscribe(::println) val flatMap = Observable.range(2, 3).flatMap { x -> Observable.range(1, 9).map { y -> String.format("%d*%d=%d", x, y, x * y) } } flatM..

val source = Observable.create { emitter: ObservableEmitter? -> emitter?.onNext("Hello") emitter?.onNext("android") emitter?.onComplete() }.subscribe(::println) // source.subscribe(::println) val source = Observable.just("Hello", "android") source.subscribe(::println) val stringList = listOf("A", "B", "C") val source = Observable.fromArray(stringList) source.subscribe(::println) val stringArrayL..

val items: PublishSubject = PublishSubject.create() items.onNext(1) items.onNext(2) items.onNext(3) items.filter { i -> i % 2 == 0 }.subscribe(::println) items.onNext(4) items.onNext(5) items.onNext(6) items.onNext(7) items.onNext(8)

class KotlinPlayGroundActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_kotlin_play_ground) val lists = listOf('a', 'f', 'd', 'w') println("toString : ${toString(lists)}") println("add : ${add(10, 15)}") println("addSecond : ${addSecond(10, 15)}") println("factorialFirst : ${Factorial.factoria..

class KotlinPlayGroundActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_kotlin_play_ground) val lists = listOf('a', 'b', 'c', 'd', 'e') println("toString : ${toString(lists, "text")}") println("toStringSecond : ${toStringSecond(lists, "text")}") println("toStringThird : ${toStringThird(lists, ..

class KotlinPlayGroundActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_kotlin_play_ground) val toothPaste = Product("ToothPast", Price(2.0), Weight(3.1)) val toothBrush = Product("ToothBrush", Price(3.0), Weight(2.5)) val orderLines = listOf( OrderLine(toothPaste, 3), OrderLine(toothBrush, 5)..