You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Eric Milles (Jira)" <ji...@apache.org> on 2020/08/08 18:46:00 UTC
[jira] [Assigned] (GROOVY-7759) @Lazy does not work when used in a
Trait
[ https://issues.apache.org/jira/browse/GROOVY-7759?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Eric Milles reassigned GROOVY-7759:
-----------------------------------
Assignee: Eric Milles
> @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)