Uploaded image for project: 'Groovy'
  1. Groovy
  2. GROOVY-1278

Call to another contructor using this(args) results in constructor running on a new object.

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 1.0-JSR-5
    • 1.0-RC-1
    • class generator
    • None
    • Windows XP, JDK1.5,

    Description

      NOTE: THE TEST CASE PASSE: however running the following code from GroovyConsole fails.

      class A {
      def a = 0
      def b = 0

      A(a)

      { this(a, 10) }

      A(a, b)

      { this.a = a this.b = b }

      }

      def a = new A(5)
      println a.a
      println a.b

      Output:
      0
      0

      The call to this(a, 10) allocates a new object, initializes it with the second contructor, and then throws it away. I verified this using JSwat and printlns.

      Again: The test case passes for some reason.

      Attachments

        1. TestThisCallInConstructor.groovy
          0.3 kB
          Edward Povazan

        Activity

          People

            blackdrag Jochen Theodorou
            emp Edward Povazan
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: