Details
-
Bug
-
Status: Closed
-
Minor
-
Resolution: Fixed
-
2.4.6
-
None
Description
@Lazy annotation is not honored when used in a trait.
Here is an example script demonstrating the issue:
class MyBase{ @Lazy String test = { 'test' }() } class TestBaseClass extends MyBase{} def tb = new TestBaseClass(); //Dump the current state to output an assert test hasn't been initialized println "Testing @Lazy on a Class.." println tb.dump() assert tb.dump().contains('test=null') //FOR A CLASS, THIS WILL SUCCEED //Access the test property causing initialization println "Accessing the test property." assert tb.test //Dump the current state to output an assert test has now been initialized println tb.dump() assert tb.test == 'test' trait MyTrait{ @Lazy String test = { 'test' }() } class TestClass implements MyTrait{} def t = new TestClass(); //Dump the current state to output an assert test hasn't been initialized println "\nTesting @Lazy on a Trait.." println t.dump() assert t.dump().contains('test=null') //FOR A TRAIT, THIS WILL FAIL THE ASSERTION - A BUG? //Access the test property causing initialization println "Accessing the test property." assert t.test //Dump the current state to output an assert test has now been initialized println t.dump() assert t.test == 'test'
Attachments
Issue Links
- is duplicated by
-
GROOVY-7760 Lazy annotation does not work with traits
- Closed