You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This differs from the behavior of lazy instance variables. The following code (note lazy instead of static) does not evaluate the closure and doesn't print anything.
I suppose so. I expect many people to have opinions here. The discrepancy between lazy and static definitely seems like a problem to me; we should pick one rule and stick with it.
This `static` setter calling the getter forces several awkward workarounds, especially with dependency injection. The `static` setter should not also call the original getter. It is very unintuitive and unsafe. Please consider fixing this so `Foo.bar = "Set"` doesn't also call the getter. The `lazy` implementation is correct.
Additional Detail from JIRA
md5: 1a0479e8c26ec52f84890efb1cc77bec
Issue Description:
When defining and evaluating a closure to initialize a variable, i.e.
to initialize a static variable, the closure is evaluated even if the variable is only set.
As a minimal example, this code will print "static"
This differs from the behavior of lazy instance variables. The following code (note
lazy
instead ofstatic
) does not evaluate the closure and doesn't print anything.The text was updated successfully, but these errors were encountered: