목록Kotlin (26)
Foggy day
class KotlinPlayGroundActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_kotlin_play_ground) val result = compose(::divide, ::multiply) println("result : ${result(3)}") val result2 = compose2(::divide, ::multiply) println("result2 : ${result2(4)}") val result3 = compose3(::divide, ::multiply) p..
class KotlinPlayGroundActivity : AppCompatActivity() { val x = 5 val y = 7 override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_kotlin_play_ground) println("jhFun_1 : ${jhFun_1(x)}") println("jhFun_2 : ${jhFun_2(x)}") println("jhFun_3 : ${jhFun_3(x)}") println("jhFun_4 : ${jhFun_4(x, y)}") println("jhFun_5 : ${jhFun_5(x)}") prin..
If you want to display multiple lines, you can use triple quotes(""") and trimMargin(). println("""Example of Jinhan : It is about String |First line |Second line |Third line |Fourth line """.trimMargin())
class KotlinPlayGroundActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_kotlin_play_ground) val message = "It is test" val length: Int = if (message is String) message.length else 100 println("length : $length") val value: Int = when (message) { is String -> message.length else -> 100 } printl..
Elvis of Kotlin is equal Optional.getOrElse() of java. you can set the default value of variable by using { ?: } class KotlinPlayGroundActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_kotlin_play_ground) var str: String? = null var strValueFirst = str ?: "It is null" println("strValueFirst : ..
class KotlinPlayGroundActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_kotlin_play_ground) val lists = listOf(1, 2, 3, 4, 5, 6, 7) println("multiplyMap : ${multiplyMap(lists)} ") println("multiplyMapSecond : ${multiplyMapSecond(lists)}") println("multiplyFold : ${multiplyFold(lists)} ") print..
Fold function have initial value. initial is 1 in this example. so, result of calFold is 25. But reduce function don't have initial value. so, result of calRecude is 24, because value of List position zero is 0. class KotlinPlayGroundActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_kotlin_pla..
class KotlinPlayGroundActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_kotlin_play_ground) println("calculate : ${calculate(3, 4)}") println("calculate2 : ${calculate2(5, 10)}") println("calculate3 : ${calculate3(20, 41)}") } fun calculate(a: Int, b: Int): Int { return a + b } fun calculate2(..
In Kotlin, there are two types immutable and mutable. The first is the immutable list. If you use +(plus) operator, plus value would be added to the list. The important thing is the fact that +(plus) operator create a new list. class KotlinPlayGroundActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.act..
If you want to create Singleton in Kotlin, just add object instead of class. Singleton can have only one instance. object(singleton) don't have constructor. object MyWindowAdapter : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) } }