イニシャライザ
class Ratioal(val numerator:Int, val dominator:Int = 1) {
init {
require(dominator != 0)
}
}
エクステンション
レシーバーとなるクラス(正確には型)の名前と関数名の間に「.」記号をおくだけです。
fun String.countWords() : Int {
this.split("""\s+""".toRegex()).size
}