Details
-
Bug
-
Status: Closed
-
Major
-
Resolution: Fixed
-
None
-
None
-
None
Description
@Delegate uses the delegate field directly but that won't have been set if also using @Lazy. We might eventually allow this to be customizable, e.g. with a flag like 'direct = false' or 'forceDirect' or 'useDelegateField', but for now we should at least just fix the common case.
Expected behavior:
class Foo { private @Delegate @Lazy ArrayList list = ['bar', 'baz'] // fragile: $list is an internal implementation detail that may change def getInternalDelegate() { $list } } def f = new Foo() assert f.internalDelegate == null assert f.size() == 2 assert f.internalDelegate == ['bar', 'baz']