2025, Oracle and/or its affiliates for (number in 1..5) { // number is the iterator and 1..5 is the range print(number) // 12345 } val cakes = listOf("carrot", "cheese", "chocolate") for (cake in cakes) { println("Yummy, it's a $cake cake!") } // Yummy, it's a carrot cake! // Yummy, it's a cheese cake! // Yummy, it's a chocolate cake! in 演算子が利用できる
2025, Oracle and/or its affiliates fun main() { val contact = Contact(1, "[email protected]") // Prints the value of the property: email println(contact.email) // [email protected] // Updates the value of the property: email contact.email = "[email protected]" // Prints the new value of the property: email println(contact.email) // [email protected] } Note; Java経験者的には、フィールドを直接扱っているこ と?と違和感があるが、実際には暗黙的に getter/setterが定義されており、必要に応じて getter/setterを追記するような形になる