LoginSignup
0
0

More than 1 year has passed since last update.

Kotlin KoansでKotlin入門 第1回:Simple Functions

Last updated at Posted at 2022-03-05

はじめに

公式の問題集「Kotlin Koans」を解きながらKotlinを学習します。

問題

Simple Functions

文字列「OK」を返すようにコードを変更してください。

fun start(): String = TODO()

解答例

TODO()を"OK"に書き換えてRUNボタンを押すとコードが実行されます。

fun start(): String = "OK"

ポイント

関数の定義に戻り値を式で指定できるようです。

戻り値の型も省略できました。

fun start() = "OK"

普通に書くとこんな感じだと思います。

fun start(): String {
    return "OK"
}
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0