Foggy day

Kotlin - function, expression syntax 본문

Kotlin

Kotlin - function, expression syntax

jinhan38 2021. 3. 16. 23:29

 

 

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(a: Int, b: Int): Int = a + b

    fun calculate3(a: Int, b: Int) = a + b

}

 

'Kotlin' 카테고리의 다른 글

Kotlin - anonymous function  (0) 2021.03.17
Kotlin - extension function, fold, reduce  (0) 2021.03.17
Kotlin - collection about immutable, mutable  (0) 2021.03.16
Kotlin - Singleton  (0) 2021.03.16
Kotlin - companion object  (0) 2021.03.16