Details
-
Type:
Bug
-
Status:
Closed
-
Priority:
Major
-
Resolution: Fixed
-
Affects Version/s: 1.7.0
-
Fix Version/s: 1.7.2, 1.6.9, 1.8-beta-1
-
Component/s: None
-
Labels:None
-
Testcase included:yes
-
Number of attachments :
Description
I'd like to use a default value in a closure argument, but at the moment,
it's not working, and I was wondering if the thing I'm trying is not
supported...
This is my code:
Sheet.metaClass.dump =
{ Integer maxRows = Integer.MAX_VALUE -> }Code from Tim Yates:
This works:
def max = Integer.MAX_VALUE
String.metaClass.dump = { Integer maxRows = max ->
delegate.substring( 0, delegate.length() < maxRows ? delegate.length() : maxRows )
}
assert 'hello'.dump( 2 ) == 'he'
assert 'hello'.dump() == 'hello'
but as you say, putting the Integer.MAX_VALUE in the closure definition throws the MissingPropertyException.
Seems to be similar to
GROOVY-1347but for closures rather than methods