jira.codehaus.org

  • Log In Access more options
    • Online Help
    • Keyboard Shortcuts
    • About JIRA
    • JIRA Credits
    • What?s New
  • Dashboards Access more options (Alt+d)
  • Projects Access more options (Alt+p)
  • Issues Access more options (Alt+i)
  • groovy
  • GROOVY-499

constructor can't invoke overloaded constructor

  • Log In
  • Views
    • XML
    • Word
    • Printable

Details

  • Type: Bug Bug
  • Status: Closed Closed
  • Priority: Major Major
  • Resolution: Fixed
  • Affects Version/s: None
  • Fix Version/s: 1.0-JSR-4
  • Component/s: None
  • Labels:
    None

Description

If groovy supports overloaded constructors, it really needs to support one constructor invoking another peer constructor. Maybe this is supported already, but trying to use "this(...)" fails. Here is my simple example:

class A {
A() { this(23) }

A {
println "entered ${i}"
}

static void main(args) { aa = new A() }
}


Running gives this error:

Caught: groovy.lang.MissingMethodException: No signature of method A.doCall() is applicable for argument types: (java.lang.Integer) values: [23]
groovy.lang.MissingMethodException: No signature of method A.doCall() is applicable for argument types: (java.lang.Integer) values: [23]
at groovy.lang.MetaClass.invokeMethod(Unknown Source)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
at org.codehaus.groovy.runtime.ReflectionMetaMethod.invoke(ReflectionMetaMethod.java:63)
at groovy.lang.MetaClass.doMethodInvoke(Unknown Source)
at groovy.lang.MetaClass.invokeMethod(Unknown Source)
at org.codehaus.groovy.runtime.Invoker.invokeMethod(Unknown Source)
at org.codehaus.groovy.runtime.InvokerHelper.invokeMethod(InvokerHelper.java:106)
at A.invokeMethod(A.groovy)
at org.codehaus.groovy.runtime.Invoker.invokeMethod(Unknown Source)
at org.codehaus.groovy.runtime.InvokerHelper.invokeClosure(InvokerHelper.java:141)
at A.<init>(A.groovy:3)
etc...



My workaround is to create another method for each constructor to call, as shown below:

class A2 {
A2() { init(23) }

A2 { init(i) }

init {
println "entered ${i}"
}

static void main(args) { aa = new A2() }
}

But this is undesirably noisey.

Another workaround is to have default parms in ctors, but this is not yet supported (JIRA issue has already been created regarding this).

Issue Links

relates to

Bug - A problem which impairs or prevents the functions of the product. GROOVY-435 Can't have private constructors

  • Major - Major loss of function.
  • Closed - The issue is considered finished, the resolution is correct. Issues which are not closed can be reopened.

Activity

Ascending order - Click to sort in descending order
  • All
  • Comments
  • Work Log
  • History
  • Activity
Hide
Permalink
Kim, Pilho added a comment - 24/Sep/05 9:37 AM

GROOVY-434 and GROOVY-499 are similar
Every class should be accessible its private (or proteced or package) creator.

Show
Kim, Pilho added a comment - 24/Sep/05 9:37 AM GROOVY-434 and GROOVY-499 are similar Every class should be accessible its private (or proteced or package) creator.
Hide
Permalink
Kim, Pilho added a comment - 25/Sep/05 8:15 PM

Here is a workaround for 1.0-jsr-04.
This should work on the build of CVS HEAD

X---------------------------------------------
class TestA {
TestA() { this(23) }

TestA {
println "entered ${i}"
}

static void main(args) { def aa = new TestA() }
}
X---------------------------------------------

Show
Kim, Pilho added a comment - 25/Sep/05 8:15 PM Here is a workaround for 1.0-jsr-04. This should work on the build of CVS HEAD X--------------------------------------------- class TestA { TestA() { this(23) } TestA { println "entered ${i}" } static void main(args) { def aa = new TestA() } } X---------------------------------------------

People

  • Assignee:
    Kim, Pilho
    Reporter:
    John Stump
Vote (2)
Watch (1)

Dates

  • Created:
    25/May/04 4:30 PM
    Updated:
    25/Sep/05 8:15 PM
    Resolved:
    24/Sep/05 9:39 AM
  • Atlassian JIRA (v5.0.4#731-sha1:3aa7374)
  • Report a problem
  • Powered by a free Atlassian JIRA open source license for Codehaus. Try JIRA - bug tracking software for your team.