@Lazygroovy annotation is typically used for a field inside an object whose time or memory is required to create. With the help of this annotation, the value of the field in the object is not calculated when creating an instance of the object, but is not calculated on the first call to obtain it.
, , @Lazy, , . ( , , ):
// without lazy annotation with this code token.length is calculated even
// is not used
class sample{
String token
Integer tokenSize = { token?.length() }()
}
def obj = new sample()
obj.token = 'aaaaaaaaaaaaaaaaaaaaaaaaaaaa'
// with Lazy annotation tokenSize is not calculated because the code
// is not getting the field.
class sample{
String token
@Lazy tokenSize = { token?.length() }()
}
def obj = new sample()
obj.token = 'aaaaaaaaaaaaaaaaaaaaaaaaaaaa'
, ,