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

Support creating instances of non-static inner classes with Java-Like syntax

    XMLWordPrintableJSON

Details

    • New Feature
    • Status: Closed
    • Major
    • Resolution: Fixed
    • None
    • 3.0.0-alpha-2, 2.6.0-alpha-4
    • None
    • None

    Description

       

      http://groovy.329449.n5.nabble.com/About-creating-instances-of-non-static-inner-classes-with-Java-Like-syntax-td5749462.html

       

      public class Y {
          public class X {
              def name
      
              public X(String name) {
                  this.name = name
              }
          }
      
          public static Y createY() {
              return new Y()
          }
      
          public static X createX(Y y) {
              return y.new X('Daniel')
          }
      
          public static X createX() {
              return createY().new X('Daniel')
          }
      
          public static String getXName() {
              return createY().new X('Daniel').name
          }
      
          public static String getXName2() {
              return createY().
                              new X('Daniel')
                                              .name
          }
      }
      
      def createY() {
          return new Y()
      }
      
      assert 'Daniel' == Y.createX(new Y()).name
      assert 'Daniel' == Y.createX().name
      assert 'Daniel' == Y.getXName()
      assert 'Daniel' == Y.getXName2()
      
      

      Attachments

        Activity

          People

            daniel_sun Daniel Sun
            daniel_sun Daniel Sun
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: