Skip to content

Instantly share code, notes, and snippets.

@Shinpeim
Created February 25, 2019 09:01
Show Gist options
  • Save Shinpeim/7989ef9f99f35a19238aa2a40639aff9 to your computer and use it in GitHub Desktop.
Save Shinpeim/7989ef9f99f35a19238aa2a40639aff9 to your computer and use it in GitHub Desktop.
import scala.util.Random
object Main {
def main(args: Array[String]): Unit = {
val a = new KlassA(new Random)
println(a.nextInt)
println(a.nextInt)
val b = new KlassB(3)
b.put
}
}
// これは?
class KlassA(r: Random){
// 呼ぶたびに結果がかわる
def nextInt: Int = r.nextInt
}
// 上のが「これは状態を持つオブジェクトを引数にとるから完全コンストラクタではない」
// となるのであれば、じゃあこれは?
class KlassB(i: Int){
// 入出力という副作用がある
def put: Unit = println(i)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment