You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "David Cole (JIRA)" <ji...@apache.org> on 2016/02/21 18:32:18 UTC
[jira] [Created] (GROOVY-7759) @Lazy does not work when used in a
Trait
David Cole created GROOVY-7759:
----------------------------------
Summary: @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
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
(v6.3.4#6332)