Details
-
Sub-task
-
Status: Open
-
Major
-
Resolution: Unresolved
-
1.7.1
-
None
-
None
-
Windows, Groovy 1.7.1
Description
If i define methods with same name and parameters on a class, one as static other as instance method, the order becomes important.
Try this in the groovy console:
class IDoNothing { } IDoNothing.metaClass.sayHello = { println "Instance says hello" } IDoNothing.metaClass.static.sayHello = { println "Class says hello" } def idn = new IDoNothing() IDoNothing.sayHello() idn.sayHello()
It will print:
Class says hello
Class says hello
although the second sayHello() was called on an instance. If you define the static method first, all works as expected:
class IDoNothing { } IDoNothing.metaClass.static.sayHello = { println "Class says hello" } IDoNothing.metaClass.sayHello = { println "Instance says hello" } def idn = new IDoNothing() IDoNothing.sayHello() idn.sayHello()
Output:
Class says hello
Instance says hello