Details
-
Bug
-
Status: Closed
-
Major
-
Resolution: Duplicate
-
None
-
None
-
None
-
None
Description
Private method of parent class can't be accessed by closure when called from a child class:
class Child extends BaseClass { static void main(String... args) { println new Child().doStuff([1,2]) } } class BaseClass { private int helper(int a) { a + 1 } def doStuff(List<Integer> numbers) { numbers.collect { helper(it) } } }
org.codehaus.groovy.runtime.InvokerInvocationException: groovy.lang.MissingMethodException: No signature of method: Child.helper() is applicable for argument types: (Integer) values: [1] Possible solutions: sleep(long), every(), grep(), every(groovy.lang.Closure), sleep(long, groovy.lang.Closure) at BaseClass.invokeMethod(Script1.groovy) Caused by: groovy.lang.MissingMethodException: No signature of method: Child.helper() is applicable for argument types: (Integer) values: [1] Possible solutions: sleep(long), every(), grep(), every(groovy.lang.Closure), sleep(long, groovy.lang.Closure) at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapter.java:70)
When using a classical foreach loop it works
class Child extends BaseClass { static void main(String... args) { println new Child().doStuff([1,2]) } } class BaseClass { private int helper(int a) { a + 1 } def doStuff(List<Integer> numbers) { def result = [] for (int it in numbers){ result << helper(it) } result } }
Removing the private modifier also fixes this problem.
Attachments
Issue Links
- duplicates
-
GROOVY-2433 Closure in base class unable to call private methods when invoked from derived class
- Closed
-
GROOVY-5438 Private field inaccessible in closure when using a subclass
- Closed