scala - Does accessing type of a lazy val cause it to be evaluated? -
scala - Does accessing type of a lazy val cause it to be evaluated? -
as question title states, accessing type
of lazy val
fellow member result in evaluation of member? or utilize static type?
here illustration code in have implicit lazy val
, , utilize type in method take implicit val
type:
implicit lazy val nonspaces: array[(point, part)]
...
def randomnonspacecoordinate(implicit nonspaces: this.nonspaces.type): point = nonspaces(utils.random.randupto(nonspaces.length))._1
let's check out:
scala> object test { | lazy val test: string = {println("bang!"); "value"} | val p: this.test.type = null | def testdef(p: this.test.type) = println(p) | } defined module test scala> test.testdef(test.p) null scala> test.testdef(test.test) bang! value
so can see accessing type not require lazy val evaluated.
scala types lazy-evaluation
Comments
Post a Comment