Created
February 25, 2019 09:01
-
-
Save Shinpeim/7989ef9f99f35a19238aa2a40639aff9 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
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