[ 
https://issues.apache.org/jira/browse/GROOVY-7759?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17173703#comment-17173703
 ] 

Eric Milles commented on GROOVY-7759:
-------------------------------------

{code:groovy}
trait T {
  @Lazy String x = { -> 'works' }()
}
class C implements T {
}
print new C().dump() // outputs"<C@52f9aa7f T__x=works>"
{code}


> @Lazy does not work when used in a Trait
> ----------------------------------------
>
>                 Key: GROOVY-7759
>                 URL: https://issues.apache.org/jira/browse/GROOVY-7759
>             Project: Groovy
>          Issue Type: Bug
>          Components: groovy-runtime
>    Affects Versions: 2.4.6
>            Reporter: David Cole
>            Assignee: Eric Milles
>            Priority: Minor
>
> @Lazy annotation is not honored when used in a trait.
> Here is an example script demonstrating the issue:
> {code}
>     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'
> {code}



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to