groovy-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Daniel Sun (JIRA)" <j...@apache.org>
Subject [jira] [Created] (GROOVY-8542) Support creating instances of non-static inner classes with Java-Like syntax
Date Thu, 12 Apr 2018 02:24:00 GMT
Daniel Sun created GROOVY-8542:
----------------------------------

             Summary: Support creating instances of non-static inner classes with Java-Like
syntax 
                 Key: GROOVY-8542
                 URL: https://issues.apache.org/jira/browse/GROOVY-8542
             Project: Groovy
          Issue Type: New Feature
            Reporter: Daniel Sun
             Fix For: 3.0.0-alpha-2, 2.6.0-alpha-4


 

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

 
{code:java}
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()

{code}



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Mime
View raw message