Created
September 11, 2022 01:13
-
-
Save 3t14/5229f069e6f03bda4070a243d8278e6f to your computer and use it in GitHub Desktop.
コメント、変数宣言
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 1行のコメント | |
// | |
/* | |
複数行のコメント | |
*/ | |
val a: Int = 1 // 値の即時割当て | |
val b = 2 // Int型への推論 | |
val c: Int // 値の割当がない場合は、型の宣言が必要 | |
// コンストラクタで初期化されない場合はエラー発生 | |
val d // 型も宣言しておらず、初期値も代入していないためエラー | |
/** | |
* You can edit, run, and share this code. | |
* play.kotlinlang.org | |
*/ | |
fun main() { | |
var a: Int = 1 // varは値の変更可能 | |
val b: Int = 2 // valは値の変更不可 | |
a = a + 1 // OK | |
b = b + 1 // NG | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment