History | Log In     View a printable version of the current page.  
Issue Details (XML | Word | Printable)

Key: GROOVY-2728
Type: Improvement Improvement
Status: Open Open
Priority: Major Major
Assignee: Graeme Rocher
Reporter: BarzilaiSpinak
Votes: 0
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
groovy

ExpandoMetaClass should allow adding methods having default parameters

Created: 05/Apr/08 01:50 AM   Updated: 05/Apr/08 03:33 AM
Component/s: None
Affects Version/s: None
Fix Version/s: 1.6

Time Tracking:
Not Specified


 Description  « Hide
This is copied from my email:
--------------

I can have a "normal" method in a class, that has default values for some of its parameters:
class A {
def someMethod(a, b, c= null) { ... }
}

This allows me to do:

def a= new A()
a.someMethod(1, 2, 3)
a.someMethod(1, 2) // third one 'c' defaults to null

If I had not defined the third param of 'someMethod' as accepting a default value, the second call would have failed with a "No signature...." exception.
So far, so good.

Now, if I want to do something similar with a method added through the MetaClass:

A.metaClass.someMeta = {a, b, c= null -> println "this is someMeta $a $b $c" }

a.someMeta(1, 2, 3) // good
a.someMeta(1, 2) // fails!!!

1) Observation number one: default-value parameters work for normal closures:

def someClo = {a, b, c= 789 -> println "clo clo $a $b $c" }

someClo(44, 55) // this one works, printing 789 for 'c'

2) Observation number two: when adding through the MetaClass you lose that feature...



 All   Comments   Work Log   Change History      Sort Order: Ascending order - Click to sort in descending order
There are no comments yet on this issue.